@@ -75,6 +75,7 @@ def __init__(
75
75
else attribute .replace ("_" , " " )
76
76
)
77
77
78
+ self .default_unit = unit
78
79
self ._attribute = attribute
79
80
self ._attr_name = f"{ super (HubitatEntity , self ).name } { attr_name } " .title ()
80
81
self ._attr_native_unit_of_measurement = unit
@@ -102,6 +103,27 @@ def _get_native_value(self) -> StateType | date | datetime | Decimal:
102
103
"""Return this sensor's current value."""
103
104
return self .get_attr (self ._attribute )
104
105
106
+ def _get_native_unit_of_measurement (self ) -> str | None :
107
+ """Return this sensor's current value."""
108
+ unit = self .default_unit
109
+ units = {
110
+ "pa" : UnitOfPressure .PA ,
111
+ "hpa" : UnitOfPressure .HPA ,
112
+ "kpa" : UnitOfPressure .KPA ,
113
+ "bar" : UnitOfPressure .BAR ,
114
+ "cbar" : UnitOfPressure .CBAR ,
115
+ "mbar" : UnitOfPressure .MBAR ,
116
+ "mmhg" : UnitOfPressure .MMHG ,
117
+ "inhg" : UnitOfPressure .INHG ,
118
+ "psi" : UnitOfPressure .PSI ,
119
+ }
120
+ attr_unit = self .get_attr_unit (self ._attribute )
121
+ if attr_unit is not None :
122
+ lower_unit = attr_unit .lower ()
123
+ if lower_unit in units :
124
+ return units [lower_unit ]
125
+ return unit
126
+
105
127
106
128
class HubitatBatterySensor (HubitatSensor ):
107
129
"""A battery sensor."""
0 commit comments