Generic hygrostat current humidity (#94912)

This commit is contained in:
Denis Shulyaka 2023-06-20 21:10:21 +03:00 committed by GitHub
parent 45616b8127
commit 1d2a973289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -248,6 +248,11 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
"""Return true if the hygrostat is on.""" """Return true if the hygrostat is on."""
return self._state return self._state
@property
def current_humidity(self):
"""Return the measured humidity."""
return self._cur_humidity
@property @property
def target_humidity(self): def target_humidity(self):
"""Return the humidity we try to reach.""" """Return the humidity we try to reach."""

View File

@ -414,16 +414,26 @@ async def test_set_away_mode_twice_and_restore_prev_humidity(
assert state.attributes.get("humidity") == 44 assert state.attributes.get("humidity") == 44
async def test_sensor_affects_attribute(hass: HomeAssistant, setup_comp_2) -> None:
"""Test that the sensor changes are reflected in the current_humidity attribute."""
state = hass.states.get(ENTITY)
assert state.attributes.get("current_humidity") == 45
_setup_sensor(hass, 47)
await hass.async_block_till_done()
state = hass.states.get(ENTITY)
assert state.attributes.get("current_humidity") == 47
async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None: async def test_sensor_bad_value(hass: HomeAssistant, setup_comp_2) -> None:
"""Test sensor that have None as state.""" """Test sensor that have None as state."""
state = hass.states.get(ENTITY) assert hass.states.get(ENTITY).state == STATE_ON
humidity = state.attributes.get("current_humidity")
_setup_sensor(hass, None) _setup_sensor(hass, None)
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get(ENTITY) assert hass.states.get(ENTITY).state == STATE_UNAVAILABLE
assert humidity == state.attributes.get("current_humidity")
async def test_set_target_humidity_humidifier_on( async def test_set_target_humidity_humidifier_on(