2024-01-16 12:31:42 +00:00
|
|
|
"""Ecovacs util functions."""
|
2024-03-08 13:15:26 +00:00
|
|
|
|
2024-01-23 20:17:18 +00:00
|
|
|
from __future__ import annotations
|
2024-01-16 12:31:42 +00:00
|
|
|
|
|
|
|
import random
|
|
|
|
import string
|
2024-01-23 20:17:18 +00:00
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
2024-02-27 08:39:49 +00:00
|
|
|
from deebot_client.capabilities import Capabilities
|
|
|
|
|
2024-01-23 20:17:18 +00:00
|
|
|
from .entity import (
|
|
|
|
EcovacsCapabilityEntityDescription,
|
|
|
|
EcovacsDescriptionEntity,
|
|
|
|
EcovacsEntity,
|
|
|
|
)
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .controller import EcovacsController
|
2024-01-16 12:31:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_client_device_id() -> str:
|
|
|
|
"""Get client device id."""
|
|
|
|
return "".join(
|
|
|
|
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
|
|
|
)
|
2024-01-23 20:17:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_supported_entitites(
|
|
|
|
controller: EcovacsController,
|
|
|
|
entity_class: type[EcovacsDescriptionEntity],
|
|
|
|
descriptions: tuple[EcovacsCapabilityEntityDescription, ...],
|
|
|
|
) -> list[EcovacsEntity]:
|
|
|
|
"""Return all supported entities for all devices."""
|
2024-03-12 17:42:43 +00:00
|
|
|
return [
|
|
|
|
entity_class(device, capability, description)
|
|
|
|
for device in controller.devices(Capabilities)
|
|
|
|
for description in descriptions
|
|
|
|
if isinstance(device.capabilities, description.device_capabilities)
|
|
|
|
if (capability := description.capability_fn(device.capabilities))
|
|
|
|
]
|