Add action attribute to generic hygrostat (#95675)
* add action attribute to generic hygrostat * Simplified initialization
This commit is contained in:
parent
b314e2b1a1
commit
7026ea643e
2 changed files with 18 additions and 0 deletions
|
@ -9,6 +9,7 @@ from homeassistant.components.humidifier import (
|
|||
MODE_AWAY,
|
||||
MODE_NORMAL,
|
||||
PLATFORM_SCHEMA,
|
||||
HumidifierAction,
|
||||
HumidifierDeviceClass,
|
||||
HumidifierEntity,
|
||||
HumidifierEntityFeature,
|
||||
|
@ -158,6 +159,7 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
|
|||
self._is_away = False
|
||||
if not self._device_class:
|
||||
self._device_class = HumidifierDeviceClass.HUMIDIFIER
|
||||
self._attr_action = HumidifierAction.IDLE
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when entity about to be added."""
|
||||
|
@ -361,6 +363,15 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
|
|||
"""Handle humidifier switch state changes."""
|
||||
if new_state is None:
|
||||
return
|
||||
|
||||
if new_state.state == STATE_ON:
|
||||
if self._device_class == HumidifierDeviceClass.DEHUMIDIFIER:
|
||||
self._attr_action = HumidifierAction.DRYING
|
||||
else:
|
||||
self._attr_action = HumidifierAction.HUMIDIFYING
|
||||
else:
|
||||
self._attr_action = HumidifierAction.IDLE
|
||||
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
async def _async_update_humidity(self, humidity):
|
||||
|
|
|
@ -121,6 +121,7 @@ async def test_humidifier_input_boolean(hass: HomeAssistant, setup_comp_1) -> No
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(humidifier_switch).state == STATE_ON
|
||||
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
|
||||
|
||||
|
||||
async def test_humidifier_switch(
|
||||
|
@ -165,6 +166,7 @@ async def test_humidifier_switch(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(humidifier_switch).state == STATE_ON
|
||||
assert hass.states.get(ENTITY).attributes.get("action") == "humidifying"
|
||||
|
||||
|
||||
def _setup_sensor(hass, humidity):
|
||||
|
@ -277,6 +279,7 @@ async def test_default_setup_params(hass: HomeAssistant, setup_comp_2) -> None:
|
|||
assert state.attributes.get("min_humidity") == 0
|
||||
assert state.attributes.get("max_humidity") == 100
|
||||
assert state.attributes.get("humidity") == 0
|
||||
assert state.attributes.get("action") == "idle"
|
||||
|
||||
|
||||
async def test_default_setup_params_dehumidifier(
|
||||
|
@ -287,6 +290,7 @@ async def test_default_setup_params_dehumidifier(
|
|||
assert state.attributes.get("min_humidity") == 0
|
||||
assert state.attributes.get("max_humidity") == 100
|
||||
assert state.attributes.get("humidity") == 100
|
||||
assert state.attributes.get("action") == "idle"
|
||||
|
||||
|
||||
async def test_get_modes(hass: HomeAssistant, setup_comp_2) -> None:
|
||||
|
@ -648,6 +652,7 @@ async def test_set_target_humidity_dry_off(hass: HomeAssistant, setup_comp_3) ->
|
|||
assert call.domain == HASS_DOMAIN
|
||||
assert call.service == SERVICE_TURN_OFF
|
||||
assert call.data["entity_id"] == ENT_SWITCH
|
||||
assert hass.states.get(ENTITY).attributes.get("action") == "drying"
|
||||
|
||||
|
||||
async def test_turn_away_mode_on_drying(hass: HomeAssistant, setup_comp_3) -> None:
|
||||
|
@ -799,6 +804,7 @@ async def test_running_when_operating_mode_is_off_2(
|
|||
assert call.domain == HASS_DOMAIN
|
||||
assert call.service == SERVICE_TURN_OFF
|
||||
assert call.data["entity_id"] == ENT_SWITCH
|
||||
assert hass.states.get(ENTITY).attributes.get("action") == "off"
|
||||
|
||||
|
||||
async def test_no_state_change_when_operation_mode_off_2(
|
||||
|
@ -818,6 +824,7 @@ async def test_no_state_change_when_operation_mode_off_2(
|
|||
_setup_sensor(hass, 45)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
assert hass.states.get(ENTITY).attributes.get("action") == "off"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
Loading…
Add table
Reference in a new issue