mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Change the way an entity is supported in La Marzocco (#108216)
* refactor supported * refactor supported
This commit is contained in:
parent
44f2b8e6a3
commit
a25653e167
@ -4,7 +4,6 @@ from collections.abc import Callable
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from lmcloud import LMCloud as LaMarzoccoClient
|
from lmcloud import LMCloud as LaMarzoccoClient
|
||||||
from lmcloud.const import LaMarzoccoModel
|
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
@ -19,12 +18,7 @@ class LaMarzoccoEntityDescription(EntityDescription):
|
|||||||
"""Description for all LM entities."""
|
"""Description for all LM entities."""
|
||||||
|
|
||||||
available_fn: Callable[[LaMarzoccoClient], bool] = lambda _: True
|
available_fn: Callable[[LaMarzoccoClient], bool] = lambda _: True
|
||||||
supported_models: tuple[LaMarzoccoModel, ...] = (
|
supported_fn: Callable[[LaMarzoccoUpdateCoordinator], bool] = lambda _: True
|
||||||
LaMarzoccoModel.GS3_AV,
|
|
||||||
LaMarzoccoModel.GS3_MP,
|
|
||||||
LaMarzoccoModel.LINEA_MICRA,
|
|
||||||
LaMarzoccoModel.LINEA_MINI,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class LaMarzoccoEntity(CoordinatorEntity[LaMarzoccoUpdateCoordinator]):
|
class LaMarzoccoEntity(CoordinatorEntity[LaMarzoccoUpdateCoordinator]):
|
||||||
|
@ -59,6 +59,7 @@ ENTITIES: tuple[LaMarzoccoSensorEntityDescription, ...] = (
|
|||||||
value_fn=lambda lm: lm.current_status.get("brew_active_duration", 0),
|
value_fn=lambda lm: lm.current_status.get("brew_active_duration", 0),
|
||||||
available_fn=lambda lm: lm.websocket_connected,
|
available_fn=lambda lm: lm.websocket_connected,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
supported_fn=lambda coordinator: coordinator.local_connection_configured,
|
||||||
),
|
),
|
||||||
LaMarzoccoSensorEntityDescription(
|
LaMarzoccoSensorEntityDescription(
|
||||||
key="current_temp_coffee",
|
key="current_temp_coffee",
|
||||||
@ -89,17 +90,11 @@ async def async_setup_entry(
|
|||||||
"""Set up sensor entities."""
|
"""Set up sensor entities."""
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
entities: list[LaMarzoccoSensorEntity] = []
|
async_add_entities(
|
||||||
for description in ENTITIES:
|
LaMarzoccoSensorEntity(coordinator, description)
|
||||||
if coordinator.lm.model_name in description.supported_models:
|
for description in ENTITIES
|
||||||
if (
|
if description.supported_fn(coordinator)
|
||||||
description.key == "shot_timer"
|
)
|
||||||
and not coordinator.local_connection_configured
|
|
||||||
):
|
|
||||||
continue
|
|
||||||
entities.append(LaMarzoccoSensorEntity(coordinator, description))
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class LaMarzoccoSensorEntity(LaMarzoccoEntity, SensorEntity):
|
class LaMarzoccoSensorEntity(LaMarzoccoEntity, SensorEntity):
|
||||||
|
@ -67,7 +67,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
LaMarzoccoSwitchEntity(coordinator, description)
|
LaMarzoccoSwitchEntity(coordinator, description)
|
||||||
for description in ENTITIES
|
for description in ENTITIES
|
||||||
if coordinator.lm.model_name in description.supported_models
|
if description.supported_fn(coordinator)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user