1 """Switch representing the shutoff valve for the Flo by Moen integration."""
3 from __future__
import annotations
7 from aioflo.location
import SLEEP_MINUTE_OPTIONS, SYSTEM_MODE_HOME, SYSTEM_REVERT_MODES
8 import voluptuous
as vol
16 from .const
import DOMAIN
as FLO_DOMAIN
17 from .coordinator
import FloDeviceDataUpdateCoordinator
18 from .entity
import FloEntity
20 ATTR_REVERT_TO_MODE =
"revert_to_mode"
21 ATTR_SLEEP_MINUTES =
"sleep_minutes"
22 SERVICE_SET_SLEEP_MODE =
"set_sleep_mode"
23 SERVICE_SET_AWAY_MODE =
"set_away_mode"
24 SERVICE_SET_HOME_MODE =
"set_home_mode"
25 SERVICE_RUN_HEALTH_TEST =
"run_health_test"
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up the Flo switches from config entry."""
34 devices: list[FloDeviceDataUpdateCoordinator] = hass.data[FLO_DOMAIN][
39 [
FloSwitch(device)
for device
in devices
if device.device_type !=
"puck_oem"]
42 platform = entity_platform.async_get_current_platform()
44 platform.async_register_entity_service(
45 SERVICE_SET_AWAY_MODE,
None,
"async_set_mode_away"
47 platform.async_register_entity_service(
48 SERVICE_SET_HOME_MODE,
None,
"async_set_mode_home"
50 platform.async_register_entity_service(
51 SERVICE_RUN_HEALTH_TEST,
None,
"async_run_health_test"
53 platform.async_register_entity_service(
54 SERVICE_SET_SLEEP_MODE,
56 vol.Required(ATTR_SLEEP_MINUTES, default=120): vol.All(
58 vol.In(SLEEP_MINUTE_OPTIONS),
60 vol.Required(ATTR_REVERT_TO_MODE, default=SYSTEM_MODE_HOME): vol.In(
64 "async_set_mode_sleep",
69 """Switch class for the Flo by Moen valve."""
71 _attr_translation_key =
"shutoff_valve"
73 def __init__(self, device: FloDeviceDataUpdateCoordinator) ->
None:
74 """Initialize the Flo switch."""
75 super().
__init__(
"shutoff_valve", device)
76 self.
_attr_is_on_attr_is_on = device.last_known_valve_state ==
"open"
80 await self._device.api_client.device.open_valve(self._device.id)
85 """Close the valve."""
86 await self._device.api_client.device.close_valve(self._device.id)
92 """Retrieve the latest valve state and update the state machine."""
93 self.
_attr_is_on_attr_is_on = self._device.last_known_valve_state ==
"open"
97 """When entity is added to hass."""
102 """Set the Flo location to home mode."""
106 """Set the Flo location to away mode."""
110 """Set the Flo location to sleep mode."""
114 """Run a Flo device health test."""
None async_update_state(self)
None async_turn_on(self, **Any kwargs)
def async_set_mode_home(self)
def async_set_mode_away(self)
def async_set_mode_sleep(self, sleep_minutes, revert_to_mode)
None async_turn_off(self, **Any kwargs)
def async_run_health_test(self)
None __init__(self, FloDeviceDataUpdateCoordinator device)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_add_listener(HomeAssistant hass, Callable[[], None] listener)