XKNX / knx-integration

Home Assistant KNX integration proxy repository
9 stars 0 forks source link

Automatically set `state_class` for sensors based on `type` #7

Open envy opened 1 month ago

envy commented 1 month ago

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:

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 commented 1 month ago

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) https://github.com/home-assistant/core/pull/53996#discussion_r683016047

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.