-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reporting minimum to be specified in device file for electricityMeter configuration #8123
Conversation
src/lib/modernExtend.ts
Outdated
export interface ElectricityMeterArgs { | ||
cluster?: 'both' | 'metering' | 'electrical'; | ||
current?: false | MultiplierDivisor; | ||
power?: false | MultiplierDivisor; | ||
power?: false | MultiplierDivisorMin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
power?: false | MultiplierDivisorMin; | |
power?: false | (MultiplierDivisor & ReportingConfigWithoutAttribute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't use ReportingConfigWithoutAttribute because its elements of min/max/change aren't optional so would need to allow all three to be specified. I was trying to make this PR the lightest touch possible. This works.
power?: false | (MultiplierDivisor & {min?: ReportingConfigTime});
src/lib/modernExtend.ts
Outdated
@@ -1836,7 +1837,7 @@ export function electricityMeter(args?: ElectricityMeterArgs): ModernExtend { | |||
// Check if this property has a divisor and multiplier, e.g. AC frequency doesn't. | |||
if ('divisor' in property) { | |||
// In case multiplier or divisor was provided, use that instead of reading from device. | |||
if (property.forced) { | |||
if (property.forced && property.forced.divisor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (property.forced && property.forced.divisor) { | |
if (property.forced?.divisor || property.forced?.multiplier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with the optional property chaining the compiler complains that:
Property 'divisor' does not exist on type 'false | MultiplierDivisor | (MultiplierDivisor & { min?: ReportingConfigTime; })'.
Property 'divisor' does not exist on type 'false'.ts(2339)
Only fix I could find was to include a test for forced:
if (property.forced && (property.forced.divisor || property.forced.multiplier)) {
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
I updated the code a bit to also allow specifying the |
Yes, this all looks good and it tests ok with my E13-A21 bulb. Thanks for your help with it. |
Thanks! |
The Sengled E13-A21 smart bulb will not report instantaneous demand unless the reporting min is set to 5 seconds or lower. The Sengled hub sets it to 3 seconds but testing shows that 5 seconds is ok. Setting it to 6 seconds or longer stops reporting.
This change allows the min value to be set in the device configuration. This was proposed here #8045 (comment)
Also included is a change to the default change value for instantaneous demand from 5 to 0.005 (kWh) as raised here #7917
Note that the Sengled bulb has a max power consumption of 12.5W so a reporting change value of 5W is still rather large and it therefore only reports on big dimmer adjustments. However I can live with that and just set that change value via the UI. The PR for the min value however isn't about optimal value, the device just won't report with the current default of 10 seconds.