1 """Platform for eq3 switch entities."""
3 from collections.abc
import Awaitable, Callable
4 from dataclasses
import dataclass
5 from typing
import TYPE_CHECKING, Any
7 from eq3btsmart
import Thermostat
8 from eq3btsmart.models
import Status
14 from .
import Eq3ConfigEntry
15 from .const
import ENTITY_KEY_AWAY, ENTITY_KEY_BOOST, ENTITY_KEY_LOCK
16 from .entity
import Eq3Entity
19 @dataclass(frozen=True, kw_only=True)
21 """Entity description for eq3 switch entities."""
23 toggle_func: Callable[[Thermostat], Callable[[bool], Awaitable[
None]]]
24 value_func: Callable[[Status], bool]
27 SWITCH_ENTITY_DESCRIPTIONS = [
30 translation_key=ENTITY_KEY_LOCK,
31 toggle_func=
lambda thermostat: thermostat.async_set_locked,
32 value_func=
lambda status: status.is_locked,
36 translation_key=ENTITY_KEY_BOOST,
37 toggle_func=
lambda thermostat: thermostat.async_set_boost,
38 value_func=
lambda status: status.is_boost,
42 translation_key=ENTITY_KEY_AWAY,
43 toggle_func=
lambda thermostat: thermostat.async_set_away,
44 value_func=
lambda status: status.is_away,
51 entry: Eq3ConfigEntry,
52 async_add_entities: AddEntitiesCallback,
54 """Set up the entry."""
58 for entity_description
in SWITCH_ENTITY_DESCRIPTIONS
63 """Base class for eq3 switch entities."""
65 entity_description: Eq3SwitchEntityDescription
69 entry: Eq3ConfigEntry,
70 entity_description: Eq3SwitchEntityDescription,
72 """Initialize the entity."""
74 super().
__init__(entry, entity_description.key)
78 """Turn on the switch."""
83 """Turn off the switch."""
89 """Return the state of the switch."""
92 assert self.
_thermostat_thermostat.status
is not None
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, Eq3ConfigEntry entry, Eq3SwitchEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, Eq3ConfigEntry entry, AddEntitiesCallback async_add_entities)