Skip to content

Commit

Permalink
Add options/possible states as extra state attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwolsink committed Nov 26, 2024
1 parent 3ae1974 commit ff880ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 7 additions & 7 deletions custom_components/aguaiot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ class AguaIOTCanalizationEntityDescription(ClimateEntityDescription):
icon="mdi:fire",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
device_class=SensorDeviceClass.ENUM,
),
AguaIOTSensorEntityDescription(
key="alarms_get",
name="Alarm",
icon="mdi:alert-outline",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
device_class=SensorDeviceClass.ENUM,
force_enabled=True,
),
AguaIOTSensorEntityDescription(
Expand All @@ -281,17 +281,17 @@ class AguaIOTCanalizationEntityDescription(ClimateEntityDescription):
icon="mdi:gauge",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
force_enabled=True,
device_class=SensorDeviceClass.ENUM,
),
AguaIOTSensorEntityDescription(
key="real_power_wood_get",
name="Real Wood Power",
icon="mdi:gauge",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
force_enabled=True,
device_class=SensorDeviceClass.ENUM,
hybrid_only=True,
),
AguaIOTSensorEntityDescription(
Expand All @@ -300,23 +300,23 @@ class AguaIOTCanalizationEntityDescription(ClimateEntityDescription):
icon="mdi:fan",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
device_class=SensorDeviceClass.ENUM,
),
AguaIOTSensorEntityDescription(
key="vent_rear2_get",
name="Real Vent Rear",
icon="mdi:fan",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
device_class=SensorDeviceClass.ENUM,
),
AguaIOTSensorEntityDescription(
key="type_combustible_get",
name="Fuel",
icon="mdi:gas-burner",
native_unit_of_measurement=None,
state_class=None,
device_class=None,
device_class=SensorDeviceClass.ENUM,
),
AguaIOTSensorEntityDescription(
key="pres_h2o_get",
Expand Down
24 changes: 22 additions & 2 deletions custom_components/aguaiot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass
from homeassistant.helpers.entity import DeviceInfo
from .const import SENSORS, DOMAIN

Expand Down Expand Up @@ -69,5 +69,25 @@ def extra_state_attributes(self):
return {
"raw_value": self._device.get_register_value(
self.entity_description.key
)
),
}

@property
def options(self):
if self.entity_description.device_class == SensorDeviceClass.ENUM:
options = sorted(
list(
set(
self._device.get_register_value_options(
self.entity_description.key
).values()
)
)
)
cur_value = self._device.get_register_value_description(
self.entity_description.key
)
if cur_value not in options:
options.append(cur_value)

return options

0 comments on commit ff880ea

Please sign in to comment.