Procházet zdrojové kódy

Climate, water_heater: improve reporting of invalid units.

If unit was static (attached to temperature / current_temperature etc
dp), there was a possibility that a None value could get reported from
another dp that was checked earlier.

Also, water_heater only checked temperature, which meany anko kettle
would report as no unit, since the config has it on the
current_temperature.

Issue #1855
Jason Rumney před 1 rokem
rodič
revize
85a737a93c

+ 9 - 9
custom_components/tuya_local/climate.py

@@ -124,27 +124,27 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
     def temperature_unit(self):
         """Return the unit of measurement."""
         # If there is a separate DPS that returns the units, use that
-        if self._unit_dps is not None:
+        if self._unit_dps:
             unit = validate_temp_unit(self._unit_dps.get_value(self._device))
             # Only return valid units
-            if unit is not None:
+            if unit:
                 return unit
         # If there unit attribute configured in the temperature dps, use that
-        if self._temperature_dps:
+        if self._temperature_dps and self._temperature_dps.unit:
             unit = validate_temp_unit(self._temperature_dps.unit)
-            if unit is not None:
+            if unit:
                 return unit
-        if self._temp_high_dps:
+        if self._temp_high_dps and self._temp_high_dps.unit:
             unit = validate_temp_unit(self._temp_high_dps.unit)
-            if unit is not None:
+            if unit:
                 return unit
-        if self._temp_low_dps:
+        if self._temp_low_dps and self._temp_low_dps.unit:
             unit = validate_temp_unit(self._temp_low_dps.unit)
             if unit is not None:
                 return unit
-        if self._current_temperature_dps:
+        if self._current_temperature_dps and self._current_temperature_dps.unit:
             unit = validate_temp_unit(self._current_temperature_dps.unit)
-            if unit is not None:
+            if unit:
                 return unit
         # Return the default unit
         return UnitOfTemperature.CELSIUS

+ 8 - 4
custom_components/tuya_local/water_heater.py

@@ -85,15 +85,19 @@ class TuyaLocalWaterHeater(TuyaLocalEntity, WaterHeaterEntity):
     def temperature_unit(self):
         """Return the unit of measurement."""
         # If there is a separate DPS that returns the units, use that
-        if self._unit_dps is not None:
+        if self._unit_dps:
             unit = validate_temp_unit(self._unit_dps.get_value(self._device))
             # Only return valid units
-            if unit is not None:
+            if unit:
                 return unit
         # If there unit attribute configured in the temperature dps, use that
-        if self._temperature_dps:
+        if self._temperature_dps and self._temperature_dps.unit:
             unit = validate_temp_unit(self._temperature_dps.unit)
-            if unit is not None:
+            if unit:
+                return unit
+        if self._current_temperature_dps and self._current_temperature_dps.unit:
+            unit = validate_temp_unit(self._current_temperature_dps.unit)
+            if unit:
                 return unit
         # Return the default unit
         return UnitOfTemperature.CELSIUS