Skip to content
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

Merged
merged 15 commits into from
Oct 17, 2024

Conversation

clockbrain
Copy link
Contributor

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.

export interface ElectricityMeterArgs {
cluster?: 'both' | 'metering' | 'electrical';
current?: false | MultiplierDivisor;
power?: false | MultiplierDivisor;
power?: false | MultiplierDivisorMin;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
power?: false | MultiplierDivisorMin;
power?: false | (MultiplierDivisor & ReportingConfigWithoutAttribute);

Copy link
Contributor Author

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});

@@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (property.forced && property.forced.divisor) {
if (property.forced?.divisor || property.forced?.multiplier) {

Copy link
Contributor Author

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)) {

src/lib/modernExtend.ts Outdated Show resolved Hide resolved
src/lib/modernExtend.ts Outdated Show resolved Hide resolved
src/lib/modernExtend.ts Outdated Show resolved Hide resolved
src/lib/modernExtend.ts Outdated Show resolved Hide resolved
clockbrain and others added 5 commits October 16, 2024 11:09
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
@Koenkk
Copy link
Owner

Koenkk commented Oct 16, 2024

I updated the code a bit to also allow specifying the max and change, can you do a final check? Then this can be merged.

@Koenkk Koenkk mentioned this pull request Oct 16, 2024
@clockbrain
Copy link
Contributor Author

Yes, this all looks good and it tests ok with my E13-A21 bulb. Thanks for your help with it.

@Koenkk Koenkk merged commit ebd3b74 into Koenkk:master Oct 17, 2024
2 checks passed
@Koenkk
Copy link
Owner

Koenkk commented Oct 17, 2024

Thanks!

@clockbrain clockbrain deleted the reporting-min branch October 20, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants