1 """Support for OpenTherm Gateway switches."""
3 from collections.abc
import Awaitable, Callable
4 from dataclasses
import dataclass
13 from .
import OpenThermGatewayHub
14 from .const
import DATA_GATEWAYS, DATA_OPENTHERM_GW, GATEWAY_DEVICE_DESCRIPTION
15 from .entity
import OpenThermEntity, OpenThermEntityDescription
18 @dataclass(frozen=True, kw_only=True)
20 OpenThermEntityDescription, SwitchEntityDescription
22 """Describes an opentherm_gw switch entity."""
24 turn_off_action: Callable[[OpenThermGatewayHub], Awaitable[int |
None]]
25 turn_on_action: Callable[[OpenThermGatewayHub], Awaitable[int |
None]]
28 SWITCH_DESCRIPTIONS: tuple[OpenThermSwitchEntityDescription, ...] = (
30 key=
"central_heating_1_override",
31 translation_key=
"central_heating_override_n",
32 translation_placeholders={
"circuit_number":
"1"},
33 device_description=GATEWAY_DEVICE_DESCRIPTION,
34 turn_off_action=
lambda hub: hub.gateway.set_ch_enable_bit(0),
35 turn_on_action=
lambda hub: hub.gateway.set_ch_enable_bit(1),
38 key=
"central_heating_2_override",
39 translation_key=
"central_heating_override_n",
40 translation_placeholders={
"circuit_number":
"2"},
41 device_description=GATEWAY_DEVICE_DESCRIPTION,
42 turn_off_action=
lambda hub: hub.gateway.set_ch2_enable_bit(0),
43 turn_on_action=
lambda hub: hub.gateway.set_ch2_enable_bit(1),
50 config_entry: ConfigEntry,
51 async_add_entities: AddEntitiesCallback,
53 """Set up the OpenTherm Gateway switches."""
54 gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
57 OpenThermSwitch(gw_hub, description)
for description
in SWITCH_DESCRIPTIONS
62 """Represent an OpenTherm Gateway switch."""
64 _attr_assumed_state =
True
65 _attr_entity_category = EntityCategory.CONFIG
66 _attr_entity_registry_enabled_default =
False
67 entity_description: OpenThermSwitchEntityDescription
70 """Turn the switch off."""
76 """Turn the switch on."""
78 self.
_attr_is_on_attr_is_on =
bool(value)
if value
is not None else None
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)