Skip to content

Commit

Permalink
Climate, water_heater: improve reporting of invalid units.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
make-all committed Jun 5, 2024
1 parent d6634c4 commit 85a737a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 9 additions & 9 deletions custom_components/tuya_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,27 @@ def __init__(self, device: TuyaLocalDevice, config: TuyaEntityConfig):
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
Expand Down
12 changes: 8 additions & 4 deletions custom_components/tuya_local/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ def supported_features(self):
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
Expand Down

0 comments on commit 85a737a

Please sign in to comment.