1
0
mirror of https://github.com/natekspencer/hacs-oasis_mini.git synced 2025-12-06 18:44:14 -05:00

Add an additional last updated diagnostic sensor for devices

This commit is contained in:
Nathan Spencer
2025-11-26 21:53:56 +00:00
parent 8a2dc8e9bc
commit dfaeb382da
4 changed files with 24 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from datetime import datetime
import logging import logging
from typing import TYPE_CHECKING, Any, Callable, Final, Iterable from typing import TYPE_CHECKING, Any, Callable, Final, Iterable
@@ -21,6 +22,7 @@ from .utils import (
create_svg, create_svg,
decrypt_svg_content, decrypt_svg_content,
get_image_url_from_track, get_image_url_from_track,
now,
) )
if TYPE_CHECKING: # avoid runtime circular imports if TYPE_CHECKING: # avoid runtime circular imports
@@ -140,6 +142,9 @@ class OasisDevice:
self._track: dict | None = None self._track: dict | None = None
self._track_task: asyncio.Task | None = None self._track_task: asyncio.Task | None = None
# Diagnostic metadata
self.last_updated: datetime | None = None
@property @property
def brightness(self) -> int: def brightness(self) -> int:
""" """
@@ -259,6 +264,8 @@ class OasisDevice:
if changed: if changed:
self._notify_listeners() self._notify_listeners()
self.last_updated = now()
def parse_status_string(self, raw_status: str) -> dict[str, Any] | None: def parse_status_string(self, raw_status: str) -> dict[str, Any] | None:
""" """
Parse a semicolon-separated device status string into a structured state dictionary. Parse a semicolon-separated device status string into a structured state dictionary.

View File

@@ -2,7 +2,10 @@
from __future__ import annotations from __future__ import annotations
from datetime import datetime
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
@@ -68,6 +71,13 @@ DESCRIPTORS = [
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=1, suggested_display_precision=1,
), ),
SensorEntityDescription(
key="last_updated",
translation_key="last_updated",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
] ]
DESCRIPTORS.extend( DESCRIPTORS.extend(
SensorEntityDescription( SensorEntityDescription(
@@ -84,7 +94,7 @@ class OasisDeviceSensorEntity(OasisDeviceEntity, SensorEntity):
"""Oasis device sensor entity.""" """Oasis device sensor entity."""
@property @property
def native_value(self) -> str | None: def native_value(self) -> str | int | float | datetime | None:
""" """
Provide the current sensor value from the underlying device. Provide the current sensor value from the underlying device.

View File

@@ -125,6 +125,9 @@
"18": "Error while downloading the job file" "18": "Error while downloading the job file"
} }
}, },
"last_updated": {
"name": "Last updated"
},
"led_color_id": { "led_color_id": {
"name": "LED color ID" "name": "LED color ID"
}, },

View File

@@ -125,6 +125,9 @@
"18": "Error while downloading the job file" "18": "Error while downloading the job file"
} }
}, },
"last_updated": {
"name": "Last updated"
},
"led_color_id": { "led_color_id": {
"name": "LED color ID" "name": "LED color ID"
}, },