From 1e8361426af9481a8b298954230bb18d87868e28 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 26 Jul 2025 13:12:07 +0300 Subject: [PATCH] Add more info to states --- xplora_ha/xplora_ha.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xplora_ha/xplora_ha.py b/xplora_ha/xplora_ha.py index e1574e2..d0eabd3 100755 --- a/xplora_ha/xplora_ha.py +++ b/xplora_ha/xplora_ha.py @@ -130,25 +130,29 @@ class XploraHa: self._publish_ha_state( f"{base_sensor_entity}last_update", { - "state": time.time() + "state": time.time(), + 'device_class': 'timestamp' } ) for watch_state in WATCH_STATES: function = getattr(self.xplora, watch_state['function']) + state = { + "state": "" + } if 'params' in watch_state: if 'date' in watch_state['params']: watch_state['params']['date'] = time.time() - state = function(watch['ward']['id'], **watch_state['params']) + state['state'] = function(watch['ward']['id'], **watch_state['params']) else: - state = function(watch['ward']['id']) + state['state'] = function(watch['ward']['id']) if 'type' in watch_state: if watch_state['type'] == 'percentage': - state = f"{state}%" + state['unit_of_measurementstate'] = "%" + elif watch_state['type'] == 'date': + state['device_class'] = 'timestamp' self._publish_ha_state( f"{base_sensor_entity}{watch_state['entity_name']}", - { - "state": state, - } + state ) def _publish_ha_state(self, entity_id, state):