Skip to content

Commit a3d5c93

Browse files
committed
Pressure entity should have valid unit_of_measurement to be supported
1 parent e918c1f commit a3d5c93

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

custom_components/yandex_smart_home/prop_float.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ class PressureProperty(FloatProperty):
181181
instance = const.FLOAT_INSTANCE_PRESSURE
182182

183183
def supported(self) -> bool:
184-
# TODO: check pressure unit
185184
if self.state.domain == sensor.DOMAIN:
186-
return self.state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PRESSURE
185+
if self.state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PRESSURE:
186+
if self.state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) in PRESSURE_TO_PASCAL:
187+
return True
187188

188189
return False
189190

tests/test_prop_float.py

+8
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,16 @@ def test_property_float_pressure(hass, yandex_pressure_unit, v):
145145
state = State('sensor.test', '740', {
146146
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE
147147
})
148+
assert_no_properties(hass, config, state, PROPERTY_FLOAT, const.FLOAT_INSTANCE_PRESSURE)
148149

150+
state = State('sensor.test', '740', {
151+
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE,
152+
ATTR_UNIT_OF_MEASUREMENT: const.PRESSURE_UNIT_MMHG
153+
})
149154
prop = get_exact_one_property(hass, config, state, PROPERTY_FLOAT, const.FLOAT_INSTANCE_PRESSURE)
155+
prop.state = State('sensor.test', '740', {
156+
ATTR_DEVICE_CLASS: DEVICE_CLASS_PRESSURE
157+
})
150158
with pytest.raises(SmartHomeError):
151159
prop.get_value()
152160

0 commit comments

Comments
 (0)