Skip to content

Commit

Permalink
Improve support climate hvac modes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Feb 12, 2025
1 parent 61f5151 commit 2e22d97
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
22 changes: 16 additions & 6 deletions custom_components/yandex_station/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ async def async_setup_entry(hass, entry, async_add_entities):
)


# HA: auto, cool, dry, fan_only, heat; heat_cool, off
# Ya: auto, cool, dry, fan_only, heat; eco, turbo, quiet
HVAC_MODES = {
"auto": HVACMode.AUTO,
"cool": HVACMode.COOL,
"dry": HVACMode.DRY,
"fan_only": HVACMode.FAN_ONLY,
"heat": HVACMode.HEAT,
}


def check_hvac_modes(item: dict) -> bool:
try:
return all(HVACMode(i["value"]) for i in item["modes"])
except ValueError:
return False
return sum(1 for i in item["modes"] if i["value"] in HVAC_MODES) >= 2


class YandexClimate(ClimateEntity, YandexEntity):
Expand Down Expand Up @@ -71,7 +79,9 @@ def internal_init(self, capabilities: dict, properties: dict):
break

if item := capabilities.get(self.hvac_instance):
self._attr_hvac_modes = [HVACMode(i["value"]) for i in item["modes"]]
self._attr_hvac_modes = [
v for i in item["modes"] if (v := HVAC_MODES.get(i["value"]))
]
elif self.device["type"] == "devices.types.purifier":
self._attr_hvac_modes = [HVACMode.FAN_ONLY]
elif "heat" in capabilities:
Expand Down Expand Up @@ -116,7 +126,7 @@ def internal_update(self, capabilities: dict, properties: dict):
if self.on_value is False:
self._attr_hvac_mode = HVACMode.OFF
elif self.hvac_value:
self._attr_hvac_mode = HVACMode(self.hvac_value)
self._attr_hvac_mode = HVAC_MODES.get(self.hvac_value)
else:
self._attr_hvac_mode = self.assumed_hvac_mode

Expand Down
50 changes: 26 additions & 24 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,25 +877,21 @@ def test_thermostat_ballu():
assert state.attributes == {
"current_temperature": None,
"friendly_name": "Кондиционер",
"hvac_modes": [HVACMode.AUTO, HVACMode.OFF],
"hvac_modes": [
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.FAN_ONLY,
HVACMode.DRY,
HVACMode.AUTO,
HVACMode.OFF,
],
"max_temp": 30,
"min_temp": 16,
"preset_mode": "auto",
"preset_modes": [
"cool",
"heat",
"fan_only",
"dry",
"auto",
"quiet",
"turbo",
"eco",
],
"supported_features": (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| TURN_ON_OFF
),
"preset_mode": "low",
"preset_modes": ["auto", "low", "medium", "high", "quiet", "turbo"],
"supported_features": ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| TURN_ON_OFF,
"target_temp_step": 1,
"temperature": 16,
}
Expand Down Expand Up @@ -1005,7 +1001,7 @@ def test_rusclimate():
"reportable": false,
"retrievable": true,
"type": "devices.capabilities.on_off",
"state": {"instance": "on", "value": false},
"state": {"instance": "on", "value": true},
"parameters": {"split": false},
"can_be_deferred": true,
},
Expand Down Expand Up @@ -1060,7 +1056,7 @@ def test_rusclimate():
"reportable": false,
"retrievable": true,
"type": "devices.capabilities.mode",
"state": {"instance": "thermostat", "value": "auto"},
"state": {"instance": "thermostat", "value": "quiet"},
"parameters": {
"instance": "thermostat",
"name": "термостат",
Expand Down Expand Up @@ -1113,19 +1109,25 @@ def test_rusclimate():
}

state = update_ha_state(YandexClimate, device, config={})
assert state.state == "off"
assert state.state == "unknown"
assert state.attributes == {
"current_temperature": 25,
"friendly_name": "Кондиционер",
"hvac_modes": [HVACMode.AUTO, HVACMode.OFF],
"hvac_modes": [
HVACMode.COOL,
HVACMode.HEAT,
HVACMode.FAN_ONLY,
HVACMode.DRY,
HVACMode.AUTO,
HVACMode.OFF,
],
"max_temp": 32,
"min_temp": 16,
"preset_mode": "auto",
"preset_modes": ["cool", "heat", "fan_only", "dry", "auto", "quiet", "eco"],
"preset_modes": ["auto", "low", "medium", "high", "turbo"],
"supported_features": ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_OFF
| ClimateEntityFeature.TURN_ON,
| TURN_ON_OFF,
"target_temp_step": 1,
"temperature": 25,
}

0 comments on commit 2e22d97

Please sign in to comment.