Add last update to aquacell (#143661)

This commit is contained in:
ngolf 2025-05-26 20:43:55 +01:00 committed by GitHub
parent 393ea0251b
commit 405725f8ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 2 deletions

View File

@ -1,6 +1,9 @@
{ {
"entity": { "entity": {
"sensor": { "sensor": {
"last_update": {
"default": "mdi:update"
},
"salt_left_side_percentage": { "salt_left_side_percentage": {
"default": "mdi:basket-fill" "default": "mdi:basket-fill"
}, },

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime
from aioaquacell import Softener from aioaquacell import Softener
@ -28,7 +29,7 @@ PARALLEL_UPDATES = 1
class SoftenerSensorEntityDescription(SensorEntityDescription): class SoftenerSensorEntityDescription(SensorEntityDescription):
"""Describes Softener sensor entity.""" """Describes Softener sensor entity."""
value_fn: Callable[[Softener], StateType] value_fn: Callable[[Softener], StateType | datetime]
SENSORS: tuple[SoftenerSensorEntityDescription, ...] = ( SENSORS: tuple[SoftenerSensorEntityDescription, ...] = (
@ -77,6 +78,12 @@ SENSORS: tuple[SoftenerSensorEntityDescription, ...] = (
"low", "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 self.entity_description = description
@property @property
def native_value(self) -> StateType: def native_value(self) -> StateType | datetime:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.entity_description.value_fn(self.softener) return self.entity_description.value_fn(self.softener)

View File

@ -21,6 +21,9 @@
}, },
"entity": { "entity": {
"sensor": { "sensor": {
"last_update": {
"name": "Last update"
},
"salt_left_side_percentage": { "salt_left_side_percentage": {
"name": "Salt left side percentage" "name": "Salt left side percentage"
}, },

View File

@ -49,6 +49,54 @@
'state': '40', 'state': '40',
}) })
# --- # ---
# name: test_sensors[sensor.aquacell_name_last_update-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'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': <ANY>,
'entity_id': 'sensor.aquacell_name_last_update',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2024-05-10T07:44:30+00:00',
})
# ---
# name: test_sensors[sensor.aquacell_name_salt_left_side_percentage-entry] # name: test_sensors[sensor.aquacell_name_salt_left_side_percentage-entry]
EntityRegistryEntrySnapshot({ EntityRegistryEntrySnapshot({
'aliases': set({ 'aliases': set({