Explorar el Código

Catit pixi: set water level device class to enum.

Since the return values are from a set of fixed strings, this is an enum.

- modify sensor.options to only return string options.  HA expects all
sensors that define options to be enum device class, and actually
abort the setup if this is not the case.  For some other devices, we
are using mappings to convert to a percentage scale for other device
classes, which we do not want to be an enum type.

Add a test to catch missing enum device classes or enum device classes
without distinct options.

Issue #455
Jason Rumney hace 3 años
padre
commit
a7e181a039

+ 1 - 0
custom_components/tuya_local/devices/catit_pixi_smart_fountain.yaml

@@ -56,6 +56,7 @@ secondary_entities:
 
   - entity: sensor
     name: Water level
+    class: enum
     category: diagnostic
     dps:
       - id: 12

+ 13 - 7
custom_components/tuya_local/sensor.py

@@ -49,12 +49,13 @@ class TuyaLocalSensor(TuyaLocalEntity, SensorEntity):
     def device_class(self):
         """Return the class of this device"""
         dclass = self._config.device_class
-        try:
-            return SensorDeviceClass(dclass)
-        except ValueError:
-            if dclass:
-                _LOGGER.warning(f"Unrecognized sensor device class of {dclass} ignored")
-            return None
+        if dclass:
+            try:
+                return SensorDeviceClass(dclass)
+            except ValueError:
+                _LOGGER.warning(
+                    "Unrecognized sensor device class of %s ignored", dclass
+                )
 
     @property
     def state_class(self):
@@ -88,4 +89,9 @@ class TuyaLocalSensor(TuyaLocalEntity, SensorEntity):
     @property
     def options(self):
         """Return a set of possible options."""
-        return self._sensor_dps.values(self._device)
+        # if mappings are all integers,  they are not options to HA
+        values = self._sensor_dps.values(self._device)
+        if values:
+            for val in values:
+                if isinstance(val, str):
+                    return values

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 449
tests/test_device_config.py


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio