1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-19 18:38:58 +00:00

Add entity picture to lamarzocco (#158518)

This commit is contained in:
Josef Zweck
2025-12-19 11:59:51 +01:00
committed by GitHub
parent d17e951591
commit 7e63c12b95
2 changed files with 34 additions and 16 deletions

View File

@@ -39,19 +39,6 @@ class LaMarzoccoSwitchEntityDescription(
ENTITIES: tuple[LaMarzoccoSwitchEntityDescription, ...] = (
LaMarzoccoSwitchEntityDescription(
key="main",
translation_key="main",
name=None,
control_fn=lambda machine, state: machine.set_power(state),
is_on_fn=(
lambda machine: cast(
MachineStatus, machine.dashboard.config[WidgetType.CM_MACHINE_STATUS]
).mode
is MachineMode.BREWING_MODE
),
bt_offline_mode=True,
),
LaMarzoccoSwitchEntityDescription(
key="steam_boiler_enable",
translation_key="steam_boiler",
@@ -98,6 +85,20 @@ ENTITIES: tuple[LaMarzoccoSwitchEntityDescription, ...] = (
),
)
MAIN_SWITCH_ENTITY = LaMarzoccoSwitchEntityDescription(
key="main",
translation_key="main",
name=None,
control_fn=lambda machine, state: machine.set_power(state),
is_on_fn=(
lambda machine: cast(
MachineStatus, machine.dashboard.config[WidgetType.CM_MACHINE_STATUS]
).mode
is MachineMode.BREWING_MODE
),
bt_offline_mode=True,
)
async def async_setup_entry(
hass: HomeAssistant,
@@ -107,12 +108,11 @@ async def async_setup_entry(
"""Set up switch entities and services."""
coordinator = entry.runtime_data.config_coordinator
bluetooth_coordinator = entry.runtime_data.bluetooth_coordinator
entities: list[SwitchEntity] = []
entities.extend(
LaMarzoccoSwitchEntity(
coordinator, description, entry.runtime_data.bluetooth_coordinator
)
LaMarzoccoSwitchEntity(coordinator, description, bluetooth_coordinator)
for description in ENTITIES
if description.supported_fn(coordinator)
)
@@ -122,6 +122,12 @@ async def async_setup_entry(
for wake_up_sleep_entry in coordinator.device.schedule.smart_wake_up_sleep.schedules
)
entities.append(
LaMarzoccoMainSwitchEntity(
coordinator, MAIN_SWITCH_ENTITY, bluetooth_coordinator
)
)
async_add_entities(entities)
@@ -160,6 +166,17 @@ class LaMarzoccoSwitchEntity(LaMarzoccoEntity, SwitchEntity):
return self.entity_description.is_on_fn(self.coordinator.device)
class LaMarzoccoMainSwitchEntity(LaMarzoccoSwitchEntity):
"""Switch representing espresso machine main power."""
@property
def entity_picture(self) -> str | None:
"""Return the entity picture."""
image_url = self.coordinator.device.dashboard.image_url
return image_url if image_url else None # image URL can be empty string
class LaMarzoccoAutoOnOffSwitchEntity(LaMarzoccoBaseEntity, SwitchEntity):
"""Switch representing espresso machine auto on/off."""

View File

@@ -133,6 +133,7 @@
# name: test_switches[switch.gs012345-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'entity_picture': 'https://lion.lamarzocco.io/img/thing-model/detail/gs3av/gs3av-1.png',
'friendly_name': 'GS012345',
}),
'context': <ANY>,