Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions homeassistant/components/generic_hygrostat/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
MODE_AWAY,
MODE_NORMAL,
PLATFORM_SCHEMA,
HumidifierAction,
HumidifierDeviceClass,
HumidifierEntity,
HumidifierEntityFeature,
Expand Down Expand Up @@ -158,6 +159,7 @@ def __init__(
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."""
Expand Down Expand Up @@ -361,6 +363,15 @@ def _async_switch_changed(self, entity_id, old_state, new_state):
"""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):
Expand Down
7 changes: 7 additions & 0 deletions tests/components/generic_hygrostat/test_humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down