Skip to content

Commit

Permalink
climate: add reporting of TURN_ON and TURN_OFF support
Browse files Browse the repository at this point in the history
In HA 2024.2, climate devices are expected to report support of
turn_on and turn_off services.

During the deprecation period until 2025.1, warnings are reported in
the log if these methods are present and the device is not reporting
this support. This change will reduce these messages to just those
devices that actually do not support the methods (using the methods
would throw an exception).

Issue #1579
  • Loading branch information
make-all committed Feb 25, 2024
1 parent 8cccb97 commit 7780ddc
Show file tree
Hide file tree
Showing 30 changed files with 88 additions and 29 deletions.
26 changes: 13 additions & 13 deletions custom_components/tuya_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,28 @@ def __init__(self, device: TuyaLocalDevice, config: TuyaEntityConfig):
self._maxtemp_dps = dps_map.pop("max_temperature", None)

self._init_end(dps_map)
self._support_flags = ClimateEntityFeature(0)

if self._aux_heat_dps:
self._support_flags |= ClimateEntityFeature.AUX_HEAT
self._attr_supported_features |= ClimateEntityFeature.AUX_HEAT
if self._fan_mode_dps:
self._support_flags |= ClimateEntityFeature.FAN_MODE
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
if self._humidity_dps:
self._support_flags |= ClimateEntityFeature.TARGET_HUMIDITY
self._attr_supported_features |= ClimateEntityFeature.TARGET_HUMIDITY
if self._preset_mode_dps:
self._support_flags |= ClimateEntityFeature.PRESET_MODE
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
if self._swing_mode_dps:
self._support_flags |= ClimateEntityFeature.SWING_MODE
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE

if self._temp_high_dps and self._temp_low_dps:
self._support_flags |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
self._attr_supported_features |= (
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
elif self._temperature_dps is not None:
self._support_flags |= ClimateEntityFeature.TARGET_TEMPERATURE

@property
def supported_features(self):
"""Return the features supported by this climate device."""
return self._support_flags
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
if HVACMode.OFF in self.hvac_modes:
self._attr_supported_features |= ClimateEntityFeature.TURN_OFF
if self._hvac_mode_dps and self._hvac_mode_dps.type is bool:
self._attr_supported_features |= ClimateEntityFeature.TURN_ON

@property
def temperature_unit(self):
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Tuya Local",
"render_readme": true,
"homeassistant": "2024.1.0"
"homeassistant": "2024.2.0"
}
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fuzzywuzzy
levenshtein
pytest-homeassistant-custom-component~=0.13.88
pytest-homeassistant-custom-component~=0.13.99
pytest
pytest-asyncio
pytest-cov
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_aspen_adv200_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_supported_features(self):
)
self.assertEqual(
self.climate.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_fan_direction(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_beca_bac002_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_supported_features(self):
ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
1 change: 1 addition & 0 deletions tests/devices/test_beca_bhp6000_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_supported_features(self):
ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
),
)

Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_beca_bht002_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_beca_bht6000_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_beok_tr9b_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_temperature_unit(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_betterlife_bl1500_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_eberg_cooly_c35hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def test_supported_features(self):
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_eberg_qubo_q40hd_heatpump.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def test_supported_features(self):
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_ecostrad_accentiq_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_temperature_unit(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_eurom_600_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_eurom_600v2_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_eurom_601_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_fersk_vind_2_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def test_supported_features(self):
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_goldair_geco_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_goldair_gpph_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_supported_features(self):
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_inkbird_sousvide.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_jiahong_et72w_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_temperature_unit(self):
Expand Down
10 changes: 8 additions & 2 deletions tests/devices/test_kogan_glass_1_7l_kettle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from homeassistant.components.climate.const import HVACMode
from homeassistant.components.climate.const import (
ClimateEntityFeature,
HVACMode,
)

from ..const import KOGAN_GLASS_1_7L_KETTLE_PAYLOAD
from ..helpers import assert_device_properties_set
Expand All @@ -20,7 +23,10 @@ def setUp(self):
self.subject = self.entities.get("climate")

def test_supported_features(self):
self.assertEqual(self.subject.supported_features, 0)
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
self.dps[HVACMODE_DPS] = True
Expand Down
5 changes: 4 additions & 1 deletion tests/devices/test_kogan_kawfpac09ya_airconditioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
(ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE),
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_moes_bht002_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_nashone_mts700wb_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_current_temperature(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_nedis_htpl20f_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_poolex_qline_heatpump.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_icon(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_starlight_heatpump.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_supported_features(self):
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.SWING_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down
5 changes: 4 additions & 1 deletion tests/devices/test_weau_pool_heatpumpv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def setUp(self):
def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE,
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
)

def test_current_temperature(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/devices/test_wetair_wch750_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def test_supported_features(self):
(
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON
),
)

Expand Down

0 comments on commit 7780ddc

Please sign in to comment.