danielsjf / awair_component

Home assistant component for Awair air quality monitor
9 stars 1 forks source link

Enhancement Request - Set device_class attribute on sensors for Homekit support #4

Open netmanchris opened 6 years ago

netmanchris commented 6 years ago

Please modify awair_component to set device classes on sensors

As per https://www.home-assistant.io/components/homekit/ various sensor are only exposed to through the Homekit driver once they meet required conditions.

Currently, device_class is not being set on the humidity, chemicals, or dust sensors. This can be manually overwritten using the customizations.yaml file but it would be great if this was set automatically within the awair_component.

Note: The chemicals is not really a pm25 sensor, but this is the closest ( air quality ) sensor that is able to be exposed to homekit.

contents of the configuration.yaml as a temp workaround.

sensor.awair2humidity: device_class: humidity sensor.bedroom_awairhumidity: device_class: humidity sensor.bedroom_glowhumidity: device_class: humidity sensor.awair2__chemicals: device_class: pm25 sensor.awair2dust: device_class: pm25 sensor.bedroom_awairchemicals: device_class: pm25 sensor.bedroom_awairdust: device_class: pm25 sensor.bedroom_glow__chemicals: device_class: pm25

danielsjf commented 6 years ago

Actually, it would be good to already ask for a change in the homekit repo. Now it says "All sensors that have pm25 as part of their entity_id or pm25 as their Device class"

However, better names would be PM2.5 and PM10 as they are a bit more scientific correct.

danielsjf commented 6 years ago

Just PM or particulate_matter are also ok

netmanchris commented 6 years ago

That wouldn't cover the humidity or the chemicals device_classes though. Seems like setting it in the awair_component is the most direct way to ensure these are exposed properly. no?

netmanchris commented 6 years ago

Did some digging, the base Entity Class does allow for the explicit setting of the device_class in the class instantiation

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/helpers/entity.py

danielsjf commented 6 years ago

Yes I meant that actually. However, I find it to be a very vague concept, these device classes. It isn't enforced and isn't standardized. You could call it humidity, or vapour or water in the air.

Anyway, those are just my two cents. Nothing stops us from aligning with homekit now since I don't think there are other guidelines.

netmanchris commented 6 years ago

LOL I'm still finding my way around the HASS components but it looks like we could consider the Homekit Component version of the device_class as the "standard" way of doing things for now?

As I dig through the code I'm also finding some other things like the ppb mapping to air quality level in the Homekit component mapping the air quality much more poorly than I would like it to be. Looks like there might be a lot of opportunity for improvement in a bunch of places here... Sounds like I might be getting more involved in Hass...

Can you add the device_class property or is this something you want me to take a shot at and submit a PR?

danielsjf commented 6 years ago

As you want. I have some time in the weekend, but feel free to submit a PR if you already want to do it immediately.