Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved enum sensors #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading