1 """Support for DROP switches."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
23 from .coordinator
import DROPDeviceDataUpdateCoordinator
24 from .entity
import DROPEntity
26 _LOGGER = logging.getLogger(__name__)
28 SWITCH_VALUE: dict[int |
None, bool] = {0:
False, 1:
True}
31 WATER_SWITCH =
"water"
32 BYPASS_SWITCH =
"bypass"
35 @dataclass(kw_only=True, frozen=True)
37 """Describes DROP switch entity."""
39 value_fn: Callable[[DROPDeviceDataUpdateCoordinator], int |
None]
40 set_fn: Callable[[DROPDeviceDataUpdateCoordinator, int], Awaitable[Any]]
43 SWITCHES: list[DROPSwitchEntityDescription] = [
46 translation_key=WATER_SWITCH,
47 value_fn=
lambda device: device.drop_api.water(),
48 set_fn=
lambda device, value: device.set_water(value),
52 translation_key=BYPASS_SWITCH,
53 value_fn=
lambda device: device.drop_api.bypass(),
54 set_fn=
lambda device, value: device.set_bypass(value),
59 DEVICE_SWITCHES: dict[str, list[str]] = {
60 DEV_FILTER: [BYPASS_SWITCH],
61 DEV_HUB: [WATER_SWITCH, BYPASS_SWITCH],
62 DEV_PROTECTION_VALVE: [WATER_SWITCH],
63 DEV_SOFTENER: [BYPASS_SWITCH],
69 config_entry: ConfigEntry,
70 async_add_entities: AddEntitiesCallback,
72 """Set up the DROP switches from config entry."""
74 "Set up switch for device type %s with entry_id is %s",
75 config_entry.data[CONF_DEVICE_TYPE],
76 config_entry.entry_id,
79 if config_entry.data[CONF_DEVICE_TYPE]
in DEVICE_SWITCHES:
81 DROPSwitch(hass.data[DOMAIN][config_entry.entry_id], switch)
82 for switch
in SWITCHES
83 if switch.key
in DEVICE_SWITCHES[config_entry.data[CONF_DEVICE_TYPE]]
88 """Representation of a DROP switch."""
90 entity_description: DROPSwitchEntityDescription
94 coordinator: DROPDeviceDataUpdateCoordinator,
95 entity_description: DROPSwitchEntityDescription,
97 """Initialize the switch."""
98 super().
__init__(entity_description.key, coordinator)
103 """Return the state of the binary sensor."""
107 """Turn switch on."""
111 """Turn switch off."""
None async_turn_off(self, **Any kwargs)
None __init__(self, DROPDeviceDataUpdateCoordinator coordinator, DROPSwitchEntityDescription entity_description)
None async_turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)