Skip to content

Commit

Permalink
Set the *native* unit of measure, for 2022.4. (#117)
Browse files Browse the repository at this point in the history
* Set the *native* unit of measure, for 2022.4.

Setting the old _attr_unit_of_measurement attribute leaves the sensors
without a unit in the new release.

* Set the sensors state_class for air quality, temperature and humidity.

This allows calculating long-term statistics, which are generally
useful.
  • Loading branch information
Flameeyes authored Apr 8, 2022
1 parent 8901107 commit 363d16a
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from libdyson.const import MessageType

from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
Expand Down Expand Up @@ -119,7 +119,7 @@ class DysonBatterySensor(DysonSensor):
_SENSOR_TYPE = "battery_level"
_SENSOR_NAME = "Battery Level"
_attr_device_class = SensorDeviceClass.BATTERY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def state(self) -> int:
Expand All @@ -134,7 +134,7 @@ class DysonFilterLifeSensor(DysonSensor):
_SENSOR_NAME = "Filter Life"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_unit_of_measurement = TIME_HOURS
_attr_native_unit_of_measurement = TIME_HOURS

@property
def state(self) -> int:
Expand All @@ -149,7 +149,7 @@ class DysonCarbonFilterLifeSensor(DysonSensor):
_SENSOR_NAME = "Carbon Filter Life"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def state(self) -> int:
Expand All @@ -164,7 +164,7 @@ class DysonHEPAFilterLifeSensor(DysonSensor):
_SENSOR_NAME = "HEPA Filter Life"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def state(self) -> int:
Expand All @@ -179,7 +179,7 @@ class DysonCombinedFilterLifeSensor(DysonSensor):
_SENSOR_NAME = "Filter Life"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def state(self) -> int:
Expand All @@ -194,7 +194,7 @@ class DysonNextDeepCleanSensor(DysonSensor):
_SENSOR_NAME = "Next Deep Clean"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_unit_of_measurement = TIME_HOURS
_attr_native_unit_of_measurement = TIME_HOURS

@property
def state(self) -> int:
Expand All @@ -208,7 +208,8 @@ class DysonHumiditySensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "humidity"
_SENSOR_NAME = "Humidity"
_attr_device_class = SensorDeviceClass.HUMIDITY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand All @@ -222,7 +223,8 @@ class DysonTemperatureSensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "temperature"
_SENSOR_NAME = "Temperature"
_attr_device_class = SensorDeviceClass.TEMPERATURE
native_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = TEMP_CELSIUS
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def temperature_kelvin(self) -> int:
Expand Down Expand Up @@ -250,7 +252,8 @@ class DysonPM25Sensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "pm25"
_SENSOR_NAME = "PM 2.5"
_attr_device_class = SensorDeviceClass.PM25
_attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand All @@ -264,7 +267,8 @@ class DysonPM10Sensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "pm10"
_SENSOR_NAME = "PM 10"
_attr_device_class = SensorDeviceClass.PM10
_attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand All @@ -278,7 +282,8 @@ class DysonParticulatesSensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "pm1"
_SENSOR_NAME = "Particulates"
_attr_device_class = SensorDeviceClass.PM1
_attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand All @@ -292,7 +297,8 @@ class DysonVOCSensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "voc"
_SENSOR_NAME = "Volatile Organic Compounds"
_attr_device_class = SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS
_attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand All @@ -306,7 +312,8 @@ class DysonNO2Sensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "no2"
_SENSOR_NAME = "Nitrogen Dioxide"
_attr_device_class = SensorDeviceClass.NITROGEN_DIOXIDE
_attr_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
_attr_state_class = SensorStateClass.MEASUREMENT

@environmental_property
def state(self) -> int:
Expand Down

0 comments on commit 363d16a

Please sign in to comment.