diff --git a/homeassistant/components/aquacell/icons.json b/homeassistant/components/aquacell/icons.json index d7383f54d72..255a964d218 100644 --- a/homeassistant/components/aquacell/icons.json +++ b/homeassistant/components/aquacell/icons.json @@ -1,6 +1,9 @@ { "entity": { "sensor": { + "last_update": { + "default": "mdi:update" + }, "salt_left_side_percentage": { "default": "mdi:basket-fill" }, diff --git a/homeassistant/components/aquacell/sensor.py b/homeassistant/components/aquacell/sensor.py index 77cd3cdd60a..58d3548284e 100644 --- a/homeassistant/components/aquacell/sensor.py +++ b/homeassistant/components/aquacell/sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations from collections.abc import Callable from dataclasses import dataclass +from datetime import datetime from aioaquacell import Softener @@ -28,7 +29,7 @@ PARALLEL_UPDATES = 1 class SoftenerSensorEntityDescription(SensorEntityDescription): """Describes Softener sensor entity.""" - value_fn: Callable[[Softener], StateType] + value_fn: Callable[[Softener], StateType | datetime] SENSORS: tuple[SoftenerSensorEntityDescription, ...] = ( @@ -77,6 +78,12 @@ SENSORS: tuple[SoftenerSensorEntityDescription, ...] = ( "low", ], ), + SoftenerSensorEntityDescription( + key="last_update", + translation_key="last_update", + device_class=SensorDeviceClass.TIMESTAMP, + value_fn=lambda softener: softener.lastUpdate, + ), ) @@ -111,6 +118,6 @@ class SoftenerSensor(AquacellEntity, SensorEntity): self.entity_description = description @property - def native_value(self) -> StateType: + def native_value(self) -> StateType | datetime: """Return the state of the sensor.""" return self.entity_description.value_fn(self.softener) diff --git a/homeassistant/components/aquacell/strings.json b/homeassistant/components/aquacell/strings.json index e07adf3c199..d2052fbd08e 100644 --- a/homeassistant/components/aquacell/strings.json +++ b/homeassistant/components/aquacell/strings.json @@ -21,6 +21,9 @@ }, "entity": { "sensor": { + "last_update": { + "name": "Last update" + }, "salt_left_side_percentage": { "name": "Salt left side percentage" }, diff --git a/tests/components/aquacell/snapshots/test_sensor.ambr b/tests/components/aquacell/snapshots/test_sensor.ambr index ec89cb34bca..f512b2a824d 100644 --- a/tests/components/aquacell/snapshots/test_sensor.ambr +++ b/tests/components/aquacell/snapshots/test_sensor.ambr @@ -49,6 +49,54 @@ 'state': '40', }) # --- +# name: test_sensors[sensor.aquacell_name_last_update-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.aquacell_name_last_update', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Last update', + 'platform': 'aquacell', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'last_update', + 'unique_id': 'DSN-last_update', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.aquacell_name_last_update-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'timestamp', + 'friendly_name': 'AquaCell name Last update', + }), + 'context': , + 'entity_id': 'sensor.aquacell_name_last_update', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '2024-05-10T07:44:30+00:00', + }) +# --- # name: test_sensors[sensor.aquacell_name_salt_left_side_percentage-entry] EntityRegistryEntrySnapshot({ 'aliases': set({