Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Make status titles available as state attribute on NibeSystemSensor (#…
Browse files Browse the repository at this point in the history
…187)

* add "statuses" as extra_state_attributes on NibeSystemSensor

* sensor description for hasStatus, with statuses attributes

* no need to check attributes_fn, defaults to lambda x: None anyway

* update state_fn of hasStatus to return number of statuses
  • Loading branch information
jelgblad authored Dec 14, 2023
1 parent 9057b6c commit 16f21a7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class NibeSystemSensorEntityDescription(SensorEntityDescription):
"""Description of a nibe system sensor."""

state_fn: Callable[[NibeSystem], StateType] = lambda x: None
attributes_fn: Callable[[NibeSystem], dict[str, str | None]] = lambda x: None


SYSTEM_SENSORS: tuple[NibeSystemSensorEntityDescription, ...] = (
Expand Down Expand Up @@ -341,6 +342,13 @@ class NibeSystemSensorEntityDescription(SensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
state_fn=lambda x: str(x.software["current"]["name"]) if x.software else None,
),
NibeSystemSensorEntityDescription(
key="statusCount",
name="status count",
entity_category=EntityCategory.DIAGNOSTIC,
state_fn=lambda x: len(x.statuses),
attributes_fn = lambda x: {"statuses": x.statuses},
),
)


Expand All @@ -367,3 +375,8 @@ def __init__(
def native_value(self) -> StateType:
"""Get the state data from system class."""
return self.entity_description.state_fn(self._system)

@property
def extra_state_attributes(self) -> dict[str, str | None]:
"""Get the attributes (extra state) data from system class."""
return self.entity_description.attributes_fn(self._system)

0 comments on commit 16f21a7

Please sign in to comment.