1 """Ecovacs button module."""
3 from dataclasses
import dataclass
5 from deebot_client.capabilities
import CapabilityExecute, CapabilityLifeSpan
6 from deebot_client.events
import LifeSpan
13 from .
import EcovacsConfigEntry
14 from .const
import SUPPORTED_LIFESPANS
16 EcovacsCapabilityEntityDescription,
17 EcovacsDescriptionEntity,
20 from .util
import get_supported_entitites
23 @dataclass(kw_only=True, frozen=True)
25 ButtonEntityDescription,
26 EcovacsCapabilityEntityDescription,
28 """Ecovacs button entity description."""
31 @dataclass(kw_only=True, frozen=True)
33 """Ecovacs lifespan button entity description."""
38 ENTITY_DESCRIPTIONS: tuple[EcovacsButtonEntityDescription, ...] = (
40 capability_fn=
lambda caps: caps.map.relocation
if caps.map
else None,
42 translation_key=
"relocate",
43 entity_category=EntityCategory.CONFIG,
47 LIFESPAN_ENTITY_DESCRIPTIONS =
tuple(
50 key=f
"reset_lifespan_{component.name.lower()}",
51 translation_key=f
"reset_lifespan_{component.name.lower()}",
52 entity_category=EntityCategory.CONFIG,
53 entity_registry_enabled_default=
False,
55 for component
in SUPPORTED_LIFESPANS
61 config_entry: EcovacsConfigEntry,
62 async_add_entities: AddEntitiesCallback,
64 """Add entities for passed config_entry in HA."""
65 controller = config_entry.runtime_data
67 controller, EcovacsButtonEntity, ENTITY_DESCRIPTIONS
71 device, device.capabilities.life_span, description
73 for device
in controller.devices
74 for description
in LIFESPAN_ENTITY_DESCRIPTIONS
75 if description.component
in device.capabilities.life_span.types
81 EcovacsDescriptionEntity[CapabilityExecute],
84 """Ecovacs button entity."""
86 entity_description: EcovacsLifespanButtonEntityDescription
89 """Press the button."""
94 EcovacsDescriptionEntity[CapabilityLifeSpan],
97 """Ecovacs reset lifespan button entity."""
99 entity_description: EcovacsLifespanButtonEntityDescription
102 """Press the button."""
103 await self.
_device_device.execute_command(
list[EcovacsEntity] get_supported_entitites(EcovacsController controller, type[EcovacsDescriptionEntity] entity_class, tuple[EcovacsCapabilityEntityDescription,...] descriptions)
def execute(hass, filename, source, data=None, return_response=False)