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

Automatically set state_class for sensors based on type #7

Open
envy opened this issue Oct 4, 2024 · 1 comment
Open

Automatically set state_class for sensors based on type #7

envy opened this issue Oct 4, 2024 · 1 comment

Comments

@envy
Copy link

envy commented Oct 4, 2024

When configuring a sensor, the state_class is optional. This can cause issues where the state_class of a sensor is not set even though it should be set.

I propose that certain types set certain state_classes if the config omits them, similar to how this is done with device_class [1].

Examples:

  • type: temperature should probably always have a state_class: measurement. Same for power, brightness, illuminance, current, etc...
  • type: active_energy should probably alway have state_class: total_increasing.

Overriding the state_class would still be possible. Removing a state_class would be harder, maybe setting the config option to false could remove it?

[1] If I understand the code correctly, the device_class is actually set in XKNX based on the sensor type/DPT.

@farmio
Copy link
Member

farmio commented Oct 4, 2024

That sounds like a good idea 👍

For reference, here is the initial implementation discussion about state_class in KNX sensor entities - and why it defaults to None (the state_class requirements / restrictions have been a bit different back then) home-assistant/core#53996 (comment)

Removing a state_class would be harder, maybe setting the config option to false could remove it?

setting it explicitly to None / null could be an option too.

If I understand the code correctly, the device_class is actually set in XKNX based on the sensor type/DPT.

Yes, but I'd like to move away from that. I think it would be better to keep HA-specifics in the HA integration and KNX specifics in xknx.

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

No branches or pull requests

2 participants