Skip to content

Commit 33c37dd

Browse files
committed
Use pressure units in events
1 parent 28b20c4 commit 33c37dd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

custom_components/hubitat/sensor.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(
7575
else attribute.replace("_", " ")
7676
)
7777

78+
self.default_unit = unit
7879
self._attribute = attribute
7980
self._attr_name = f"{super(HubitatEntity, self).name} {attr_name}".title()
8081
self._attr_native_unit_of_measurement = unit
@@ -102,6 +103,27 @@ def _get_native_value(self) -> StateType | date | datetime | Decimal:
102103
"""Return this sensor's current value."""
103104
return self.get_attr(self._attribute)
104105

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+
105127

106128
class HubitatBatterySensor(HubitatSensor):
107129
"""A battery sensor."""

0 commit comments

Comments
 (0)