99from homeassistant .components .fan import FanEntity , FanEntityFeature
1010from homeassistant .components .sensor import SensorDeviceClass , SensorEntity
1111from homeassistant .components .switch import SwitchDeviceClass , SwitchEntity
12+ from homeassistant .const import (
13+ EVENT_HOMEASSISTANT_STOP ,
14+ PERCENTAGE ,
15+ SIGNAL_STRENGTH_DECIBELS ,
16+ EntityCategory ,
17+ UnitOfElectricCurrent ,
18+ UnitOfElectricPotential ,
19+ UnitOfEnergy ,
20+ UnitOfPower ,
21+ UnitOfTemperature ,
22+ CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ,
23+ )
1224
1325from dirigera import Hub
1426from dirigera .devices .blinds import Blind
@@ -118,11 +130,11 @@ def schedule_update_ha_state(self, force_refresh:bool = False) -> None:
118130 listener .schedule_update_ha_state (force_refresh )
119131
120132class ikea_base_device_sensor ():
121- def __init__ (self , device , id_suffix :str = "" , name :str = "" , uom = "" , icon = "" , device_class = None , entity_category = None , state_class = None ):
133+ def __init__ (self , device , id_suffix :str = "" , name :str = "" , native_unit_of_measurement = "" , icon = "" , device_class = None , entity_category = None , state_class = None ):
122134 self ._device = device
123135 self ._name = name
124136 self ._id_suffix = id_suffix
125- self ._uom = uom
137+ self ._native_unit_of_measurement = native_unit_of_measurement
126138 self ._device_class = device_class
127139 self ._entity_category = entity_category
128140 self ._state_class = state_class
@@ -169,7 +181,7 @@ def icon(self):
169181
170182 @property
171183 def native_unit_of_measurement (self ) -> str :
172- return self ._uom
184+ return self ._native_unit_of_measurement
173185
174186 async def async_update (self ):
175187 await self ._device .async_update ()
@@ -366,7 +378,7 @@ def __init__(self, device: ikea_vindstyrka_device) -> None:
366378 id_suffix = "TEMP" ,
367379 name = "Temperature" ,
368380 device_class = SensorDeviceClass .TEMPERATURE ,
369- uom = "°C" ,
381+ native_unit_of_measurement = UnitOfTemperature . CELSIUS ,
370382 state_class = "measurement" )
371383 logger .debug ("ikea_vindstyrka_temperature ctor..." )
372384
@@ -382,7 +394,7 @@ def __init__(self, device: ikea_vindstyrka_device) -> None:
382394 id_suffix = "HUM" ,
383395 name = "Humidity" ,
384396 device_class = SensorDeviceClass .HUMIDITY ,
385- uom = "%" )
397+ native_unit_of_measurement = PERCENTAGE )
386398
387399 @property
388400 def native_value (self ) -> int :
@@ -415,7 +427,7 @@ def __init__(
415427 id_suffix = id_suffix ,
416428 name = name_suffix ,
417429 device_class = SensorDeviceClass .PM25 ,
418- uom = "µg/m³" )
430+ native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER )
419431
420432 @property
421433 def native_value (self ) -> int :
@@ -436,7 +448,7 @@ def __init__(self, device: ikea_vindstyrka_device) -> None:
436448 id_suffix = "VOC" ,
437449 name = "VOC Index" ,
438450 device_class = SensorDeviceClass .VOLATILE_ORGANIC_COMPOUNDS ,
439- uom = "µg/m³" )
451+ native_unit_of_measurement = CONCENTRATION_MICROGRAMS_PER_CUBIC_METER )
440452
441453 @property
442454 def native_value (self ) -> int :
@@ -643,7 +655,7 @@ def __init__(
643655 prefix : str ,
644656 device_class : SensorDeviceClass ,
645657 native_value_prop : str ,
646- native_uom : str ,
658+ native_unit_of_measurement : str ,
647659 icon_name : str ,
648660 ):
649661 logger .debug ("ikea_starkvind_air_purifier_sensor ctor ..." )
@@ -652,7 +664,7 @@ def __init__(
652664 id_suffix = prefix ,
653665 name = prefix ,
654666 device_class = device_class ,
655- uom = native_uom ,
667+ native_unit_of_measurement = native_uom ,
656668 icon = icon_name )
657669
658670 self ._native_value_prop = native_value_prop
@@ -744,7 +756,9 @@ def __init__(self, device):
744756 device = device ,
745757 id_suffix = "BP01" ,
746758 name = "Battery Percentage" ,
747- uom = "%" ,
759+ native_unit_of_measurement = PERCENTAGE ,
760+ state_class = SensorStateClass .MEASUREMENT ,
761+ #uom="%",
748762 device_class = SensorDeviceClass .BATTERY ,
749763 entity_category = EntityCategory .DIAGNOSTIC )
750764
@@ -758,7 +772,9 @@ def __init__(self, device):
758772 device = device ,
759773 id_suffix = "CA01" ,
760774 name = "Current Amps" ,
761- uom = "A" ,
775+ #uom="A",
776+ native_unit_of_measurement = UnitOfElectricCurrent .AMPERE ,
777+ state_class = SensorStateClass .MEASUREMENT ,
762778 icon = "mdi:current-ac" ,
763779 device_class = SensorDeviceClass .CURRENT )
764780
@@ -772,7 +788,7 @@ def __init__(self, device):
772788 device = device ,
773789 id_suffix = "CAP01" ,
774790 name = "Current Active Power" ,
775- uom = "W" ,
791+ native_unit_of_measurement = UnitOfPower . WATT ,
776792 icon = "mdi:lightning-bolt-outline" ,
777793 device_class = SensorDeviceClass .POWER )
778794
@@ -781,15 +797,15 @@ def native_value(self):
781797 return getattr (self ._device , "current_active_power" )
782798
783799class current_voltage_sensor (ikea_base_device_sensor , SensorEntity ):
784- def __init__ (self , device ):
785- super ().__init__ (device ,"current_voltage" ,"CV01" ,SensorDeviceClass .VOLTAGE ,"V" ,"Current Voltage" ,"mdi:power-plug" )
786800
787801 def __init__ (self , device ):
788802 super ().__init__ (
789803 device = device ,
790804 id_suffix = "CV01" ,
791805 name = "Current Voltage" ,
792- uom = "V" ,
806+ #uom="V",
807+ native_unit_of_measurement = UnitOfElectricPotential .VOLT ,
808+ state_class = SensorStateClass .MEASUREMENT ,
793809 icon = "mdi:power-plug" ,
794810 device_class = SensorDeviceClass .VOLTAGE )
795811
@@ -803,7 +819,7 @@ def __init__(self, device):
803819 device = device ,
804820 id_suffix = "TEC01" ,
805821 name = "Total Energy Consumed" ,
806- uom = "kWh" ,
822+ native_unit_of_measurement = UnitOfEnergy . KILO_WATT_HOUR ,
807823 icon = "mdi:lightning-bolt-outline" ,
808824 device_class = SensorDeviceClass .ENERGY ,
809825 state_class = SensorStateClass .TOTAL_INCREASING )
@@ -818,7 +834,7 @@ def __init__(self, device):
818834 device = device ,
819835 id_suffix = "ELAR01" ,
820836 name = "Energy Consumed at Last Reset" ,
821- uom = "kWh" ,
837+ native_unit_of_measurement = UnitOfEnergy . KILO_WATT_HOUR ,
822838 icon = "mdi:lightning-bolt-outline" ,
823839 device_class = SensorDeviceClass .ENERGY ,
824840 state_class = SensorStateClass .TOTAL_INCREASING )
@@ -832,6 +848,7 @@ def __init__(self, device):
832848 super ().__init__ (
833849 device = device ,
834850 id_suffix = "TLER01" ,
851+ device_class = SensorDeviceClass .TIMESTAMP ,
835852 name = "Time of Last Energy Reset" ,
836853 icon = "mdi:update" )
837854
@@ -863,12 +880,14 @@ def __init__(self, device):
863880 super ().__init__ ( device ,
864881 id_suffix = "TECLU01" ,
865882 name = "Total Energy Consumed Last Updated" ,
883+ device_class = SensorDeviceClass .TIMESTAMP ,
866884 icon = "mdi:update" )
867885
868886 def __init__ (self , device ):
869887 super ().__init__ (
870888 device = device ,
871889 id_suffix = "TECLU01" ,
890+ device_class = SensorDeviceClass .TIMESTAMP ,
872891 name = "Time Energy Consumed Last Updated" ,
873892 icon = "mdi:update" )
874893
0 commit comments