mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Humidifier turn display off for sleep mode (#137133)
This commit is contained in:
parent
7f69c689bf
commit
9a565885cb
@ -157,11 +157,15 @@ class VeSyncHumidifierHA(VeSyncBaseEntity, HumidifierEntity):
|
||||
"""Set the mode of the device."""
|
||||
if mode not in self.available_modes:
|
||||
raise HomeAssistantError(
|
||||
"{mode} is not one of the valid available modes: {self.available_modes}"
|
||||
f"{mode} is not one of the valid available modes: {self.available_modes}"
|
||||
)
|
||||
if not self.device.set_humidity_mode(self._get_vs_mode(mode)):
|
||||
raise HomeAssistantError(f"An error occurred while setting mode {mode}.")
|
||||
|
||||
if mode == MODE_SLEEP:
|
||||
# We successfully changed the mode. Consider it a success even if display operation fails.
|
||||
self.device.set_display(False)
|
||||
|
||||
# Changing mode while humidifier is off actually turns it on, as per the app. But
|
||||
# the library does not seem to update the device_status. It is also possible that
|
||||
# other attributes get updated. Scheduling a forced refresh to get device status.
|
||||
|
@ -10,9 +10,16 @@ from homeassistant.components.humidifier import (
|
||||
ATTR_HUMIDITY,
|
||||
ATTR_MODE,
|
||||
DOMAIN as HUMIDIFIER_DOMAIN,
|
||||
MODE_AUTO,
|
||||
MODE_SLEEP,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_SET_MODE,
|
||||
)
|
||||
from homeassistant.components.vesync.const import (
|
||||
VS_HUMIDIFIER_MODE_AUTO,
|
||||
VS_HUMIDIFIER_MODE_MANUAL,
|
||||
VS_HUMIDIFIER_MODE_SLEEP,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
@ -222,7 +229,7 @@ async def test_set_mode(
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_SET_MODE,
|
||||
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER, ATTR_MODE: "auto"},
|
||||
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER, ATTR_MODE: MODE_AUTO},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
@ -285,3 +292,38 @@ async def test_valid_mist_modes(
|
||||
await hass.async_block_till_done()
|
||||
assert "Unknown mode 'auto'" not in caplog.text
|
||||
assert "Unknown mode 'manual'" not in caplog.text
|
||||
|
||||
|
||||
async def test_set_mode_sleep_turns_display_off(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
humidifier,
|
||||
manager,
|
||||
) -> None:
|
||||
"""Test update of display for sleep mode."""
|
||||
|
||||
# First define valid mist modes
|
||||
humidifier.mist_modes = [
|
||||
VS_HUMIDIFIER_MODE_AUTO,
|
||||
VS_HUMIDIFIER_MODE_MANUAL,
|
||||
VS_HUMIDIFIER_MODE_SLEEP,
|
||||
]
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.vesync.async_generate_device_list",
|
||||
return_value=[humidifier],
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with (
|
||||
patch.object(humidifier, "set_humidity_mode", return_value=True),
|
||||
patch.object(humidifier, "set_display") as display_mock,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
HUMIDIFIER_DOMAIN,
|
||||
SERVICE_SET_MODE,
|
||||
{ATTR_ENTITY_ID: ENTITY_HUMIDIFIER, ATTR_MODE: MODE_SLEEP},
|
||||
blocking=True,
|
||||
)
|
||||
display_mock.assert_called_once_with(False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user