mirror of
https://github.com/home-assistant/core.git
synced 2025-12-20 02:48:57 +00:00
Add entity picture to lamarzocco (#158518)
This commit is contained in:
@@ -39,19 +39,6 @@ class LaMarzoccoSwitchEntityDescription(
|
|||||||
|
|
||||||
|
|
||||||
ENTITIES: tuple[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(
|
LaMarzoccoSwitchEntityDescription(
|
||||||
key="steam_boiler_enable",
|
key="steam_boiler_enable",
|
||||||
translation_key="steam_boiler",
|
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(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@@ -107,12 +108,11 @@ async def async_setup_entry(
|
|||||||
"""Set up switch entities and services."""
|
"""Set up switch entities and services."""
|
||||||
|
|
||||||
coordinator = entry.runtime_data.config_coordinator
|
coordinator = entry.runtime_data.config_coordinator
|
||||||
|
bluetooth_coordinator = entry.runtime_data.bluetooth_coordinator
|
||||||
|
|
||||||
entities: list[SwitchEntity] = []
|
entities: list[SwitchEntity] = []
|
||||||
entities.extend(
|
entities.extend(
|
||||||
LaMarzoccoSwitchEntity(
|
LaMarzoccoSwitchEntity(coordinator, description, bluetooth_coordinator)
|
||||||
coordinator, description, entry.runtime_data.bluetooth_coordinator
|
|
||||||
)
|
|
||||||
for description in ENTITIES
|
for description in ENTITIES
|
||||||
if description.supported_fn(coordinator)
|
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
|
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)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
@@ -160,6 +166,17 @@ class LaMarzoccoSwitchEntity(LaMarzoccoEntity, SwitchEntity):
|
|||||||
return self.entity_description.is_on_fn(self.coordinator.device)
|
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):
|
class LaMarzoccoAutoOnOffSwitchEntity(LaMarzoccoBaseEntity, SwitchEntity):
|
||||||
"""Switch representing espresso machine auto on/off."""
|
"""Switch representing espresso machine auto on/off."""
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@
|
|||||||
# name: test_switches[switch.gs012345-state]
|
# name: test_switches[switch.gs012345-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
|
'entity_picture': 'https://lion.lamarzocco.io/img/thing-model/detail/gs3av/gs3av-1.png',
|
||||||
'friendly_name': 'GS012345',
|
'friendly_name': 'GS012345',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
|
|||||||
Reference in New Issue
Block a user