1 """Support for TechnoVE switches."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
6 from dataclasses
import dataclass
9 from technove
import Station
as TechnoVEStation
17 from .
import TechnoVEConfigEntry
18 from .const
import DOMAIN
19 from .coordinator
import TechnoVEDataUpdateCoordinator
20 from .entity
import TechnoVEEntity
21 from .helpers
import technove_exception_handler
25 coordinator: TechnoVEDataUpdateCoordinator, enabled: bool
27 if coordinator.data.info.auto_charge:
29 translation_domain=DOMAIN,
30 translation_key=
"set_charging_enabled_on_auto_charge",
32 await coordinator.technove.set_charging_enabled(enabled=enabled)
33 coordinator.data.info.is_session_active = enabled
34 coordinator.async_set_updated_data(coordinator.data)
46 coordinator: TechnoVEDataUpdateCoordinator, enabled: bool
48 await coordinator.technove.set_auto_charge(enabled=enabled)
51 @dataclass(frozen=True, kw_only=True)
53 """Describes TechnoVE binary sensor entity."""
55 is_on_fn: Callable[[TechnoVEStation], bool]
56 turn_on_fn: Callable[[TechnoVEDataUpdateCoordinator], Coroutine[Any, Any,
None]]
57 turn_off_fn: Callable[[TechnoVEDataUpdateCoordinator], Coroutine[Any, Any,
None]]
63 translation_key=
"auto_charge",
64 entity_category=EntityCategory.CONFIG,
65 is_on_fn=
lambda station: station.info.auto_charge,
71 translation_key=
"session_active",
72 entity_category=EntityCategory.CONFIG,
73 is_on_fn=
lambda station: station.info.is_session_active,
74 turn_on_fn=_enable_charging,
75 turn_off_fn=_disable_charging,
82 entry: TechnoVEConfigEntry,
83 async_add_entities: AddEntitiesCallback,
85 """Set up TechnoVE switch based on a config entry."""
89 for description
in SWITCHES
94 """Defines a TechnoVE switch entity."""
96 entity_description: TechnoVESwitchDescription
100 coordinator: TechnoVEDataUpdateCoordinator,
101 description: TechnoVESwitchDescription,
103 """Initialize a TechnoVE switch entity."""
105 super().
__init__(coordinator, description.key)
109 """Return the state of the TechnoVE switch."""
113 @technove_exception_handler
115 """Turn on the TechnoVE switch."""
118 @technove_exception_handler
120 """Turn off the TechnoVE switch."""
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, TechnoVEDataUpdateCoordinator coordinator, TechnoVESwitchDescription description)
None _disable_charging(TechnoVEDataUpdateCoordinator coordinator)
None _set_auto_charge(TechnoVEDataUpdateCoordinator coordinator, bool enabled)
None _enable_charging(TechnoVEDataUpdateCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, TechnoVEConfigEntry entry, AddEntitiesCallback async_add_entities)
None _set_charging_enabled(TechnoVEDataUpdateCoordinator coordinator, bool enabled)