1 """Switch platform for Ecoforest."""
3 from __future__
import annotations
5 from collections.abc
import Awaitable, Callable
6 from dataclasses
import dataclass
9 from pyecoforest.api
import EcoforestApi
10 from pyecoforest.models.device
import Device
17 from .const
import DOMAIN
18 from .coordinator
import EcoforestCoordinator
19 from .entity
import EcoforestEntity
22 @dataclass(frozen=True, kw_only=True)
24 """Describes an Ecoforest switch entity."""
26 value_fn: Callable[[Device], bool]
27 switch_fn: Callable[[EcoforestApi, bool], Awaitable[Device]]
30 SWITCH_TYPES: tuple[EcoforestSwitchEntityDescription, ...] = (
34 value_fn=
lambda data: data.on,
35 switch_fn=
lambda api, status: api.turn(status),
42 config_entry: ConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up Ecoforest switch platform."""
46 coordinator: EcoforestCoordinator = hass.data[DOMAIN][config_entry.entry_id]
56 """Representation of an Ecoforest switch entity."""
58 entity_description: EcoforestSwitchEntityDescription
62 """Return the state of the ecoforest device."""
66 """Turn on the ecoforest device."""
71 """Turn off the ecoforest device."""
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)