From e149aa6b2e14917a120977e72b6943db08c4bc81 Mon Sep 17 00:00:00 2001 From: Josef Zweck <24647999+zweckj@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:27:22 +0200 Subject: [PATCH] Add backflush sensor to lamarzocco (#119888) Co-authored-by: Joost Lekkerkerker --- .../components/lamarzocco/binary_sensor.py | 7 +++ homeassistant/components/lamarzocco/button.py | 1 + .../components/lamarzocco/icons.json | 6 +++ .../components/lamarzocco/strings.json | 3 ++ .../snapshots/test_binary_sensor.ambr | 47 +++++++++++++++++++ .../lamarzocco/test_binary_sensor.py | 1 + 6 files changed, 65 insertions(+) diff --git a/homeassistant/components/lamarzocco/binary_sensor.py b/homeassistant/components/lamarzocco/binary_sensor.py index 2ad72ea4087..81ac3672a0f 100644 --- a/homeassistant/components/lamarzocco/binary_sensor.py +++ b/homeassistant/components/lamarzocco/binary_sensor.py @@ -45,6 +45,13 @@ ENTITIES: tuple[LaMarzoccoBinarySensorEntityDescription, ...] = ( available_fn=lambda device: device.websocket_connected, entity_category=EntityCategory.DIAGNOSTIC, ), + LaMarzoccoBinarySensorEntityDescription( + key="backflush_enabled", + translation_key="backflush_enabled", + device_class=BinarySensorDeviceClass.RUNNING, + is_on_fn=lambda config: config.backflush_enabled, + entity_category=EntityCategory.DIAGNOSTIC, + ), ) diff --git a/homeassistant/components/lamarzocco/button.py b/homeassistant/components/lamarzocco/button.py index c261630836e..7b38c9fbf72 100644 --- a/homeassistant/components/lamarzocco/button.py +++ b/homeassistant/components/lamarzocco/button.py @@ -56,3 +56,4 @@ class LaMarzoccoButtonEntity(LaMarzoccoEntity, ButtonEntity): async def async_press(self) -> None: """Press button.""" await self.entity_description.press_fn(self.coordinator.device) + await self.coordinator.async_request_refresh() diff --git a/homeassistant/components/lamarzocco/icons.json b/homeassistant/components/lamarzocco/icons.json index 965ee7e3c3f..bc7d621d91d 100644 --- a/homeassistant/components/lamarzocco/icons.json +++ b/homeassistant/components/lamarzocco/icons.json @@ -14,6 +14,12 @@ "on": "mdi:cup-water", "off": "mdi:cup-off" } + }, + "backflush_enabled": { + "default": "mdi:water-off", + "state": { + "on": "mdi:water" + } } }, "button": { diff --git a/homeassistant/components/lamarzocco/strings.json b/homeassistant/components/lamarzocco/strings.json index f6b979a30ae..08e3e764379 100644 --- a/homeassistant/components/lamarzocco/strings.json +++ b/homeassistant/components/lamarzocco/strings.json @@ -54,6 +54,9 @@ }, "entity": { "binary_sensor": { + "backflush_enabled": { + "name": "Backflush active" + }, "brew_active": { "name": "Brewing active" }, diff --git a/tests/components/lamarzocco/snapshots/test_binary_sensor.ambr b/tests/components/lamarzocco/snapshots/test_binary_sensor.ambr index f08c2c28851..df47ac002e6 100644 --- a/tests/components/lamarzocco/snapshots/test_binary_sensor.ambr +++ b/tests/components/lamarzocco/snapshots/test_binary_sensor.ambr @@ -1,4 +1,51 @@ # serializer version: 1 +# name: test_binary_sensors[GS01234_backflush_active-binary_sensor] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'running', + 'friendly_name': 'GS01234 Backflush active', + }), + 'context': , + 'entity_id': 'binary_sensor.gs01234_backflush_active', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_binary_sensors[GS01234_backflush_active-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': , + 'entity_id': 'binary_sensor.gs01234_backflush_active', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Backflush active', + 'platform': 'lamarzocco', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'backflush_enabled', + 'unique_id': 'GS01234_backflush_enabled', + 'unit_of_measurement': None, + }) +# --- # name: test_binary_sensors[GS01234_brewing_active-binary_sensor] StateSnapshot({ 'attributes': ReadOnlyDict({ diff --git a/tests/components/lamarzocco/test_binary_sensor.py b/tests/components/lamarzocco/test_binary_sensor.py index 36acde91a68..d363b96ca21 100644 --- a/tests/components/lamarzocco/test_binary_sensor.py +++ b/tests/components/lamarzocco/test_binary_sensor.py @@ -18,6 +18,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed BINARY_SENSORS = ( "brewing_active", + "backflush_active", "water_tank_empty", )