Plugwise HVAC/Preset mode fixes (#66273)
This commit is contained in:
parent
18056325bb
commit
b8253b1b47
3 changed files with 32 additions and 17 deletions
|
@ -21,13 +21,11 @@ from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN, SCHEDULE_OFF, SCHEDULE_ON
|
from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN
|
||||||
from .coordinator import PlugwiseDataUpdateCoordinator
|
from .coordinator import PlugwiseDataUpdateCoordinator
|
||||||
from .entity import PlugwiseEntity
|
from .entity import PlugwiseEntity
|
||||||
from .util import plugwise_command
|
from .util import plugwise_command
|
||||||
|
|
||||||
HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO, HVAC_MODE_OFF]
|
|
||||||
HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_AUTO, HVAC_MODE_OFF]
|
|
||||||
THERMOSTAT_CLASSES = ["thermostat", "zone_thermostat", "thermostatic_radiator_valve"]
|
THERMOSTAT_CLASSES = ["thermostat", "zone_thermostat", "thermostatic_radiator_valve"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,10 +48,7 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
|
||||||
|
|
||||||
_attr_max_temp = DEFAULT_MAX_TEMP
|
_attr_max_temp = DEFAULT_MAX_TEMP
|
||||||
_attr_min_temp = DEFAULT_MIN_TEMP
|
_attr_min_temp = DEFAULT_MIN_TEMP
|
||||||
_attr_preset_modes = None
|
|
||||||
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
|
||||||
_attr_temperature_unit = TEMP_CELSIUS
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
_attr_hvac_modes = HVAC_MODES_HEAT_ONLY
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -67,12 +62,17 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
|
||||||
self._attr_name = self.device.get("name")
|
self._attr_name = self.device.get("name")
|
||||||
|
|
||||||
# Determine preset modes
|
# Determine preset modes
|
||||||
|
self._attr_supported_features = SUPPORT_TARGET_TEMPERATURE
|
||||||
if presets := self.device.get("presets"):
|
if presets := self.device.get("presets"):
|
||||||
|
self._attr_supported_features |= SUPPORT_PRESET_MODE
|
||||||
self._attr_preset_modes = list(presets)
|
self._attr_preset_modes = list(presets)
|
||||||
|
|
||||||
# Determine hvac modes and current hvac mode
|
# Determine hvac modes and current hvac mode
|
||||||
|
self._attr_hvac_modes = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
||||||
if self.coordinator.data.gateway.get("cooling_present"):
|
if self.coordinator.data.gateway.get("cooling_present"):
|
||||||
self._attr_hvac_modes = HVAC_MODES_HEAT_COOL
|
self._attr_hvac_modes.append(HVAC_MODE_COOL)
|
||||||
|
if self.device.get("available_schedules") != ["None"]:
|
||||||
|
self._attr_hvac_modes.append(HVAC_MODE_AUTO)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self) -> float | None:
|
def current_temperature(self) -> float | None:
|
||||||
|
@ -130,16 +130,20 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
|
||||||
@plugwise_command
|
@plugwise_command
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
"""Set the hvac mode."""
|
"""Set the hvac mode."""
|
||||||
state = SCHEDULE_OFF
|
|
||||||
if hvac_mode == HVAC_MODE_AUTO:
|
if hvac_mode == HVAC_MODE_AUTO:
|
||||||
state = SCHEDULE_ON
|
if (
|
||||||
|
schedule_temperature := self.device.get("schedule_temperature")
|
||||||
|
) is None:
|
||||||
|
raise ValueError("Cannot set HVAC mode to Auto: No schedule available")
|
||||||
|
|
||||||
await self.coordinator.api.set_temperature(
|
await self.coordinator.api.set_temperature(
|
||||||
self.device["location"], self.device.get("schedule_temperature")
|
self.device["location"], schedule_temperature
|
||||||
)
|
)
|
||||||
self._attr_target_temperature = self.device.get("schedule_temperature")
|
|
||||||
|
|
||||||
await self.coordinator.api.set_schedule_state(
|
await self.coordinator.api.set_schedule_state(
|
||||||
self.device["location"], self.device.get("last_used"), state
|
self.device["location"],
|
||||||
|
self.device.get("last_used"),
|
||||||
|
"true" if hvac_mode == HVAC_MODE_AUTO else "false",
|
||||||
)
|
)
|
||||||
|
|
||||||
@plugwise_command
|
@plugwise_command
|
||||||
|
|
|
@ -14,8 +14,6 @@ FLOW_STRETCH = "stretch (Stretch)"
|
||||||
FLOW_TYPE = "flow_type"
|
FLOW_TYPE = "flow_type"
|
||||||
GATEWAY = "gateway"
|
GATEWAY = "gateway"
|
||||||
PW_TYPE = "plugwise_type"
|
PW_TYPE = "plugwise_type"
|
||||||
SCHEDULE_OFF = "false"
|
|
||||||
SCHEDULE_ON = "true"
|
|
||||||
SMILE = "smile"
|
SMILE = "smile"
|
||||||
STRETCH = "stretch"
|
STRETCH = "stretch"
|
||||||
STRETCH_USERNAME = "stretch"
|
STRETCH_USERNAME = "stretch"
|
||||||
|
|
|
@ -5,6 +5,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_AUTO,
|
HVAC_MODE_AUTO,
|
||||||
|
HVAC_MODE_COOL,
|
||||||
HVAC_MODE_HEAT,
|
HVAC_MODE_HEAT,
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
)
|
)
|
||||||
|
@ -22,7 +23,7 @@ async def test_adam_climate_entity_attributes(hass, mock_smile_adam):
|
||||||
state = hass.states.get("climate.zone_lisa_wk")
|
state = hass.states.get("climate.zone_lisa_wk")
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
|
|
||||||
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_AUTO, HVAC_MODE_OFF]
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_AUTO]
|
||||||
|
|
||||||
assert "preset_modes" in attrs
|
assert "preset_modes" in attrs
|
||||||
assert "no_frost" in attrs["preset_modes"]
|
assert "no_frost" in attrs["preset_modes"]
|
||||||
|
@ -38,7 +39,7 @@ async def test_adam_climate_entity_attributes(hass, mock_smile_adam):
|
||||||
state = hass.states.get("climate.zone_thermostat_jessie")
|
state = hass.states.get("climate.zone_thermostat_jessie")
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
|
|
||||||
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_AUTO, HVAC_MODE_OFF]
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_AUTO]
|
||||||
|
|
||||||
assert "preset_modes" in attrs
|
assert "preset_modes" in attrs
|
||||||
assert "no_frost" in attrs["preset_modes"]
|
assert "no_frost" in attrs["preset_modes"]
|
||||||
|
@ -157,7 +158,7 @@ async def test_anna_climate_entity_attributes(hass, mock_smile_anna):
|
||||||
attrs = state.attributes
|
attrs = state.attributes
|
||||||
|
|
||||||
assert "hvac_modes" in attrs
|
assert "hvac_modes" in attrs
|
||||||
assert "heat" in attrs["hvac_modes"]
|
assert attrs["hvac_modes"] == [HVAC_MODE_HEAT, HVAC_MODE_OFF, HVAC_MODE_COOL]
|
||||||
|
|
||||||
assert "preset_modes" in attrs
|
assert "preset_modes" in attrs
|
||||||
assert "no_frost" in attrs["preset_modes"]
|
assert "no_frost" in attrs["preset_modes"]
|
||||||
|
@ -214,3 +215,15 @@ async def test_anna_climate_entity_climate_changes(hass, mock_smile_anna):
|
||||||
mock_smile_anna.set_schedule_state.assert_called_with(
|
mock_smile_anna.set_schedule_state.assert_called_with(
|
||||||
"c784ee9fdab44e1395b8dee7d7a497d5", None, "false"
|
"c784ee9fdab44e1395b8dee7d7a497d5", None, "false"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Auto mode is not available, no schedules
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
await hass.services.async_call(
|
||||||
|
"climate",
|
||||||
|
"set_hvac_mode",
|
||||||
|
{"entity_id": "climate.anna", "hvac_mode": "auto"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert mock_smile_anna.set_temperature.call_count == 1
|
||||||
|
assert mock_smile_anna.set_schedule_state.call_count == 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue