mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +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 lmcloud import LMCloud as LaMarzoccoClient
|
||||
from lmcloud.const import LaMarzoccoModel
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
@ -19,12 +18,7 @@ class LaMarzoccoEntityDescription(EntityDescription):
|
||||
"""Description for all LM entities."""
|
||||
|
||||
available_fn: Callable[[LaMarzoccoClient], bool] = lambda _: True
|
||||
supported_models: tuple[LaMarzoccoModel, ...] = (
|
||||
LaMarzoccoModel.GS3_AV,
|
||||
LaMarzoccoModel.GS3_MP,
|
||||
LaMarzoccoModel.LINEA_MICRA,
|
||||
LaMarzoccoModel.LINEA_MINI,
|
||||
)
|
||||
supported_fn: Callable[[LaMarzoccoUpdateCoordinator], bool] = lambda _: True
|
||||
|
||||
|
||||
class LaMarzoccoEntity(CoordinatorEntity[LaMarzoccoUpdateCoordinator]):
|
||||
|
@ -59,6 +59,7 @@ ENTITIES: tuple[LaMarzoccoSensorEntityDescription, ...] = (
|
||||
value_fn=lambda lm: lm.current_status.get("brew_active_duration", 0),
|
||||
available_fn=lambda lm: lm.websocket_connected,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
supported_fn=lambda coordinator: coordinator.local_connection_configured,
|
||||
),
|
||||
LaMarzoccoSensorEntityDescription(
|
||||
key="current_temp_coffee",
|
||||
@ -89,17 +90,11 @@ async def async_setup_entry(
|
||||
"""Set up sensor entities."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities: list[LaMarzoccoSensorEntity] = []
|
||||
for description in ENTITIES:
|
||||
if coordinator.lm.model_name in description.supported_models:
|
||||
if (
|
||||
description.key == "shot_timer"
|
||||
and not coordinator.local_connection_configured
|
||||
):
|
||||
continue
|
||||
entities.append(LaMarzoccoSensorEntity(coordinator, description))
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
LaMarzoccoSensorEntity(coordinator, description)
|
||||
for description in ENTITIES
|
||||
if description.supported_fn(coordinator)
|
||||
)
|
||||
|
||||
|
||||
class LaMarzoccoSensorEntity(LaMarzoccoEntity, SensorEntity):
|
||||
|
@ -67,7 +67,7 @@ async def async_setup_entry(
|
||||
async_add_entities(
|
||||
LaMarzoccoSwitchEntity(coordinator, description)
|
||||
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