From 95f2331cc3e312ebf43539583dc745581e18d3f1 Mon Sep 17 00:00:00 2001 From: Patrick762 Date: Sat, 19 Aug 2023 22:38:30 +0200 Subject: [PATCH] fixed enum sensors --- README.md | 3 ++- custom_components/bluetti_bt/sensor.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 63fcd9e..87b1f25 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,5 @@ All sensors which are available in bluetti_mqtt (Based on [this file](https://gi excluding battery pack fields. ### Available controls: -AC and DC outputs (for now) +If enabled in the Integration options (you need to reload the integration if you change this option): +AC and DC outputs diff --git a/custom_components/bluetti_bt/sensor.py b/custom_components/bluetti_bt/sensor.py index 902145f..66ca581 100644 --- a/custom_components/bluetti_bt/sensor.py +++ b/custom_components/bluetti_bt/sensor.py @@ -1,6 +1,7 @@ """Bluetti BT sensors.""" from __future__ import annotations +from enum import Enum import logging from decimal import Decimal @@ -146,6 +147,7 @@ class BluettiSensor(CoordinatorEntity, SensorEntity): and not isinstance(response_data, float) and not isinstance(response_data, complex) and not isinstance(response_data, Decimal) + and not isinstance(response_data, Enum) ): _LOGGER.warning( "Invalid response data type from coordinator (sensor.%s): %s has type %s", @@ -161,11 +163,11 @@ class BluettiSensor(CoordinatorEntity, SensorEntity): # Different for enum and numeric if ( self._options is not None - and isinstance(response_data, int) - and response_data < len(self._options) + and isinstance(response_data, Enum) + and response_data.value < len(self._options) ): # Enum - self._attr_native_value = self._options[response_data] + self._attr_native_value = self._options[response_data.value] else: # Numeric self._attr_native_value = response_data