Skip to content

Commit

Permalink
Improved enum sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Apr 15, 2024
1 parent 49007d2 commit 42657dc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion custom_components/goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from typing import Any

from goodwe import Inverter, Sensor, SensorKind
from goodwe.sensor import Enum, Enum2, EnumBitmap22, EnumBitmap4, EnumCalculated, EnumH, EnumL

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
Expand Down Expand Up @@ -157,6 +159,10 @@ class GoodweSensorEntityDescription(SensorEntityDescription):
TEXT_SENSOR = GoodweSensorEntityDescription(
key="text",
)
ENUM_SENSOR = GoodweSensorEntityDescription(
key="enum",
device_class=SensorDeviceClass.ENUM,
)


async def async_setup_entry(
Expand Down Expand Up @@ -203,7 +209,20 @@ def __init__(
try:
self.entity_description = _DESCRIPTIONS[sensor.unit]
except KeyError:
if "Enum" in type(sensor).__name__ or sensor.id_ == "timestamp":
if (
isinstance(sensor, Enum)
or isinstance(sensor, EnumH)
or isinstance(sensor, EnumL)
or isinstance(sensor, Enum2)
or isinstance(sensor, EnumCalculated)
):
self.entity_description = ENUM_SENSOR
self._attr_options = list(sensor._labels.values())
elif (
isinstance(sensor, EnumBitmap4)
or isinstance(sensor, EnumBitmap22)
or sensor.id_ == "timestamp"
):
self.entity_description = TEXT_SENSOR
else:
self.entity_description = DIAG_SENSOR
Expand Down

0 comments on commit 42657dc

Please sign in to comment.