mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix humidifier on off status update (#135743)
This commit is contained in:
parent
a8cb618f96
commit
54e4e8a7bb
@ -149,12 +149,16 @@ class VeSyncHumidifierHA(VeSyncBaseEntity, HumidifierEntity):
|
|||||||
if not success:
|
if not success:
|
||||||
raise HomeAssistantError("An error occurred while turning on.")
|
raise HomeAssistantError("An error occurred while turning on.")
|
||||||
|
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs: Any) -> None:
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
success = self.device.turn_off()
|
success = self.device.turn_off()
|
||||||
if not success:
|
if not success:
|
||||||
raise HomeAssistantError("An error occurred while turning off.")
|
raise HomeAssistantError("An error occurred while turning off.")
|
||||||
|
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return True if device is on."""
|
"""Return True if device is on."""
|
||||||
|
@ -108,41 +108,73 @@ async def test_set_target_humidity(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("turn_on", "api_response", "expectation"),
|
("api_response", "expectation"),
|
||||||
[
|
[(False, pytest.raises(HomeAssistantError)), (True, NoException)],
|
||||||
(False, False, pytest.raises(HomeAssistantError)),
|
|
||||||
(False, True, NoException),
|
|
||||||
(True, False, pytest.raises(HomeAssistantError)),
|
|
||||||
(True, True, NoException),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
async def test_turn_on_off(
|
async def test_turn_on(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
humidifier_config_entry: MockConfigEntry,
|
humidifier_config_entry: MockConfigEntry,
|
||||||
turn_on: bool,
|
|
||||||
api_response: bool,
|
api_response: bool,
|
||||||
expectation,
|
expectation,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test turn_on/off methods."""
|
"""Test turn_on method."""
|
||||||
|
|
||||||
# turn_on/turn_off returns False indicating failure in which case humidifier.turn_on/turn_off
|
# turn_on returns False indicating failure in which case humidifier.turn_on
|
||||||
# raises HomeAssistantError.
|
# raises HomeAssistantError.
|
||||||
with (
|
with (
|
||||||
expectation,
|
expectation,
|
||||||
patch(
|
patch(
|
||||||
f"pyvesync.vesyncfan.VeSyncHumid200300S.{'turn_on' if turn_on else 'turn_off'}",
|
"pyvesync.vesyncfan.VeSyncHumid200300S.turn_on", return_value=api_response
|
||||||
return_value=api_response,
|
|
||||||
) as method_mock,
|
) as method_mock,
|
||||||
):
|
):
|
||||||
await hass.services.async_call(
|
with patch(
|
||||||
HUMIDIFIER_DOMAIN,
|
"homeassistant.components.vesync.humidifier.VeSyncHumidifierHA.schedule_update_ha_state"
|
||||||
SERVICE_TURN_ON if turn_on else SERVICE_TURN_OFF,
|
) as update_mock:
|
||||||
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER},
|
await hass.services.async_call(
|
||||||
blocking=True,
|
HUMIDIFIER_DOMAIN,
|
||||||
)
|
SERVICE_TURN_ON,
|
||||||
|
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
method_mock.assert_called_once()
|
method_mock.assert_called_once()
|
||||||
|
update_mock.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("api_response", "expectation"),
|
||||||
|
[(False, pytest.raises(HomeAssistantError)), (True, NoException)],
|
||||||
|
)
|
||||||
|
async def test_turn_off(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
humidifier_config_entry: MockConfigEntry,
|
||||||
|
api_response: bool,
|
||||||
|
expectation,
|
||||||
|
) -> None:
|
||||||
|
"""Test turn_off method."""
|
||||||
|
|
||||||
|
# turn_off returns False indicating failure in which case humidifier.turn_off
|
||||||
|
# raises HomeAssistantError.
|
||||||
|
with (
|
||||||
|
expectation,
|
||||||
|
patch(
|
||||||
|
"pyvesync.vesyncfan.VeSyncHumid200300S.turn_off", return_value=api_response
|
||||||
|
) as method_mock,
|
||||||
|
):
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.vesync.humidifier.VeSyncHumidifierHA.schedule_update_ha_state"
|
||||||
|
) as update_mock:
|
||||||
|
await hass.services.async_call(
|
||||||
|
HUMIDIFIER_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
method_mock.assert_called_once()
|
||||||
|
update_mock.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_set_mode_invalid(
|
async def test_set_mode_invalid(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user