* migrate to 1.1 * bump to 1.1.1 * fix newlines docstring * cleanup entity_description fns * strict generics * restructure import * tweaks to generics * tweaks to generics * removed exceptions * move initialization, websocket clean shutdown * get rid of duplicate entry addign * bump lmcloud * re-add calendar, auto on/off switches * use asdict for diagnostics * change number generator * use name as entry title * also migrate title * don't migrate title * remove generics for now * satisfy mypy * add s * adapt * migrate entry.runtime_data * remove auto/onoff * add issue on wrong gw firmware * silence mypy * remove breaks in ha version * parametrize issue test * Update update.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * regen snapshots * mapping steam level * remove commented code * fix typo * coderabbitai availability tweak * remove microsecond moving * additonal schedule for coverage * be more specific on date offset * keep mappings the same * config_entry imports sharpened * remove unneccessary testcase, clenup date moving * remove superfluous calendar testcase from diag * guard against future version downgrade * use new entry for downgrade test * switch to lmcloud 1.1.11 * revert runtimedata * revert runtimedata * version to helper * conistent Generator * generator from typing_extensions --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""Base class for the La Marzocco entities."""
|
|
|
|
from collections.abc import Callable
|
|
from dataclasses import dataclass
|
|
|
|
from lmcloud.const import FirmwareType
|
|
from lmcloud.lm_machine import LaMarzoccoMachine
|
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.entity import EntityDescription
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import DOMAIN
|
|
from .coordinator import LaMarzoccoUpdateCoordinator
|
|
|
|
|
|
@dataclass(frozen=True, kw_only=True)
|
|
class LaMarzoccoEntityDescription(EntityDescription):
|
|
"""Description for all LM entities."""
|
|
|
|
available_fn: Callable[[LaMarzoccoMachine], bool] = lambda _: True
|
|
supported_fn: Callable[[LaMarzoccoUpdateCoordinator], bool] = lambda _: True
|
|
|
|
|
|
class LaMarzoccoBaseEntity(
|
|
CoordinatorEntity[LaMarzoccoUpdateCoordinator],
|
|
):
|
|
"""Common elements for all entities."""
|
|
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: LaMarzoccoUpdateCoordinator,
|
|
key: str,
|
|
) -> None:
|
|
"""Initialize the entity."""
|
|
super().__init__(coordinator)
|
|
device = coordinator.device
|
|
self._attr_unique_id = f"{device.serial_number}_{key}"
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={(DOMAIN, device.serial_number)},
|
|
name=device.name,
|
|
manufacturer="La Marzocco",
|
|
model=device.full_model_name,
|
|
serial_number=device.serial_number,
|
|
sw_version=device.firmware[FirmwareType.MACHINE].current_version,
|
|
)
|
|
|
|
|
|
class LaMarzoccoEntity(LaMarzoccoBaseEntity):
|
|
"""Common elements for all entities."""
|
|
|
|
entity_description: LaMarzoccoEntityDescription
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
"""Return True if entity is available."""
|
|
if super().available:
|
|
return self.entity_description.available_fn(self.coordinator.device)
|
|
return False
|
|
|
|
def __init__(
|
|
self,
|
|
coordinator: LaMarzoccoUpdateCoordinator,
|
|
entity_description: LaMarzoccoEntityDescription,
|
|
) -> None:
|
|
"""Initialize the entity."""
|
|
super().__init__(coordinator, entity_description.key)
|
|
self.entity_description = entity_description
|