1 """Switcher integration Button platform."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
6 from dataclasses
import dataclass
7 from typing
import Any, cast
9 from aioswitcher.api
import (
15 from aioswitcher.api.remotes
import SwitcherBreezeRemote
16 from aioswitcher.device
import DeviceCategory
25 from .
import SwitcherConfigEntry
26 from .const
import SIGNAL_DEVICE_ADD
27 from .coordinator
import SwitcherDataUpdateCoordinator
28 from .entity
import SwitcherEntity
29 from .utils
import get_breeze_remote_manager
32 @dataclass(frozen=True, kw_only=True)
34 """Class to describe a Switcher Thermostat Button entity."""
37 [SwitcherApi, SwitcherBreezeRemote],
38 Coroutine[Any, Any, SwitcherBaseResponse],
40 supported: Callable[[SwitcherBreezeRemote], bool]
43 THERMOSTAT_BUTTONS = [
46 translation_key=
"assume_on",
47 entity_category=EntityCategory.CONFIG,
48 press_fn=
lambda api, remote: api.control_breeze_device(
49 remote, state=DeviceState.ON, update_state=
True
51 supported=
lambda _:
True,
55 translation_key=
"assume_off",
56 entity_category=EntityCategory.CONFIG,
57 press_fn=
lambda api, remote: api.control_breeze_device(
58 remote, state=DeviceState.OFF, update_state=
True
60 supported=
lambda _:
True,
63 key=
"vertical_swing_on",
64 translation_key=
"vertical_swing_on",
65 press_fn=
lambda api, remote: api.control_breeze_device(
66 remote, swing=ThermostatSwing.ON
68 supported=
lambda remote: bool(remote.separated_swing_command),
71 key=
"vertical_swing_off",
72 translation_key=
"vertical_swing_off",
73 press_fn=
lambda api, remote: api.control_breeze_device(
74 remote, swing=ThermostatSwing.OFF
76 supported=
lambda remote: bool(remote.separated_swing_command),
83 config_entry: SwitcherConfigEntry,
84 async_add_entities: AddEntitiesCallback,
86 """Set up Switcher button from config entry."""
88 async
def async_add_buttons(coordinator: SwitcherDataUpdateCoordinator) ->
None:
89 """Get remote and add button from Switcher device."""
90 data = cast(SwitcherBreezeRemote, coordinator.data)
91 if coordinator.data.device_type.category == DeviceCategory.THERMOSTAT:
92 remote: SwitcherBreezeRemote = await hass.async_add_executor_job(
97 for description
in THERMOSTAT_BUTTONS
98 if description.supported(remote)
101 config_entry.async_on_unload(
107 """Representation of a Switcher climate entity."""
109 entity_description: SwitcherThermostatButtonEntityDescription
113 coordinator: SwitcherDataUpdateCoordinator,
114 description: SwitcherThermostatButtonEntityDescription,
115 remote: SwitcherBreezeRemote,
117 """Initialize the entity."""
125 """Press the button."""
126 response: SwitcherBaseResponse |
None =
None
130 async
with SwitcherApi(
131 self.coordinator.data.device_type,
132 self.coordinator.data.ip_address,
133 self.coordinator.data.device_id,
134 self.coordinator.data.device_key,
137 except (TimeoutError, OSError, RuntimeError)
as err:
140 if error
or not response
or not response.successful:
141 self.coordinator.last_update_success =
False
144 f
"Call api for {self.name} failed, response/error: {response or error}"
None async_write_ha_state(self)
SwitcherBreezeRemoteManager get_breeze_remote_manager(HomeAssistant hass)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)