enkama / hass-variables

Home Assistant variables component
90 stars 12 forks source link

Add device class and unit of measurement #66

Closed Snuffy2 closed 1 year ago

Snuffy2 commented 1 year ago

Notes:

  1. If a Device Class for a Sensor is set, the Value must be of the type that is required by the Device Class (ex. for a Device Class of Duration the Value must be a Number). This is enforced both when creating the Sensor Variable and when updating the Value of the Sensor Variable with the variable.update_sensor service.
  2. If a Device Class for a Sensor is set and a Unit of Measurement is not set, Home Assistant will give a Warning.
  3. If the Device Class of a Sensor is changed and the new Device Class requires a different type of Value, the old Value will be cleared.
Snuffy2 commented 1 year ago

@Wibias not sure if you want to release this as a beta first?

Snuffy2 commented 1 year ago

Uncovered some additional issues. Hold on this PR until I sort them out and push fixes.

Snuffy2 commented 1 year ago

Turns out it was the same root cause for all of the problems I was seeing and the fix was pretty small. I think it's ready for review again. Thanks.

enkama commented 1 year ago

Ready for merge? If yes what do we do about flake error? Just ignore it? If yes feel free to add # noqa: C901 at the end of l19!

Snuffy2 commented 1 year ago

Yes, I believe it is ready to go. I added the noqa line for now. I may split it up in the future to reduce complexity, but not terribly high on my priority list honestly.