Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HVACMode.OFF to Plugwise Adam #103360

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 61 additions & 18 deletions homeassistant/components/plugwise/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class PlugwiseClimateEntity(PlugwiseEntity, ClimateEntity):
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_translation_key = DOMAIN

_previous_mode: str = "heating"

def __init__(
self,
coordinator: PlugwiseDataUpdateCoordinator,
Expand All @@ -55,10 +57,15 @@ def __init__(
super().__init__(coordinator, device_id)
self._attr_extra_state_attributes = {}
self._attr_unique_id = f"{device_id}-climate"

self.cdr_gateway = coordinator.data.gateway
gateway_id: str = coordinator.data.gateway["gateway_id"]
self.gateway_data = coordinator.data.devices[gateway_id]
# Determine supported features
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
if self.coordinator.data.gateway["cooling_present"]:
if (
self.cdr_gateway["cooling_present"]
and self.cdr_gateway["smile_name"] != "Adam"
):
self._attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
Expand All @@ -73,6 +80,20 @@ def __init__(
self.device["thermostat"]["resolution"], 0.1
)

def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> None:
"""Return the previous action-mode when the regulation-mode is not heating or cooling.

Helper for set_hvac_mode().
"""
# When no cooling available, _previous_mode is always heating
if (
"regulation_modes" in self.gateway_data
and "cooling" in self.gateway_data["regulation_modes"]
):
mode = self.gateway_data["select_regulation_mode"]
if mode in ("cooling", "heating"):
self._previous_mode = mode

@property
def current_temperature(self) -> float:
"""Return the current temperature."""
Expand Down Expand Up @@ -105,33 +126,46 @@ def target_temperature_low(self) -> float:

@property
def hvac_mode(self) -> HVACMode:
"""Return HVAC operation ie. auto, heat, or heat_cool mode."""
"""Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
if (mode := self.device.get("mode")) is None or mode not in self.hvac_modes:
return HVACMode.HEAT
return HVACMode(mode)

@property
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available HVACModes."""
hvac_modes = [HVACMode.HEAT]
if self.coordinator.data.gateway["cooling_present"]:
hvac_modes = [HVACMode.HEAT_COOL]
"""Return a list of available HVACModes."""
hvac_modes: list[HVACMode] = []
if "regulation_modes" in self.gateway_data:
hvac_modes.append(HVACMode.OFF)

if self.device["available_schedules"] != ["None"]:
hvac_modes.append(HVACMode.AUTO)

if self.cdr_gateway["cooling_present"]:
if "regulation_modes" in self.gateway_data:
if self.gateway_data["select_regulation_mode"] == "cooling":
hvac_modes.append(HVACMode.COOL)
if self.gateway_data["select_regulation_mode"] == "heating":
hvac_modes.append(HVACMode.HEAT)
else:
hvac_modes.append(HVACMode.HEAT_COOL)
else:
hvac_modes.append(HVACMode.HEAT)

return hvac_modes

@property
def hvac_action(self) -> HVACAction | None:
def hvac_action(self) -> HVACAction:
"""Return the current running hvac operation if supported."""
heater: str | None = self.coordinator.data.gateway["heater_id"]
if heater:
heater_data = self.coordinator.data.devices[heater]
if heater_data["binary_sensors"]["heating_state"]:
return HVACAction.HEATING
if heater_data["binary_sensors"].get("cooling_state"):
return HVACAction.COOLING
# Keep track of the previous action-mode
self._previous_action_mode(self.coordinator)

heater: str = self.coordinator.data.gateway["heater_id"]
heater_data = self.coordinator.data.devices[heater]
if heater_data["binary_sensors"]["heating_state"]:
return HVACAction.HEATING
if heater_data["binary_sensors"].get("cooling_state", False):
return HVACAction.COOLING

return HVACAction.IDLE

Expand Down Expand Up @@ -168,9 +202,18 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if hvac_mode not in self.hvac_modes:
raise HomeAssistantError("Unsupported hvac_mode")

await self.coordinator.api.set_schedule_state(
self.device["location"], "on" if hvac_mode == HVACMode.AUTO else "off"
)
if hvac_mode == self.hvac_mode:
return

if hvac_mode == HVACMode.OFF:
await self.coordinator.api.set_regulation_mode(hvac_mode)
else:
await self.coordinator.api.set_schedule_state(
self.device["location"],
"on" if hvac_mode == HVACMode.AUTO else "off",
)
if self.hvac_mode == HVACMode.OFF:
await self.coordinator.api.set_regulation_mode(self._previous_mode)

@plugwise_command
async def async_set_preset_mode(self, preset_mode: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/plugwise/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"loggers": ["crcmod", "plugwise"],
"requirements": ["plugwise==0.33.2"],
"requirements": ["plugwise==0.34.0"],
"zeroconf": ["_plugwise._tcp.local."]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ plexauth==0.0.6
plexwebsocket==0.0.14

# homeassistant.components.plugwise
plugwise==0.33.2
plugwise==0.34.0

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ plexauth==0.0.6
plexwebsocket==0.0.14

# homeassistant.components.plugwise
plugwise==0.33.2
plugwise==0.34.0

# homeassistant.components.plum_lightpad
plumlightpad==0.0.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"firmware": "2016-10-27T02:00:00+02:00",
"hardware": "255",
"location": "06aecb3d00354375924f50c47af36bd2",
"mode": "heat",
"mode": "off",
"model": "Lisa",
"name": "Slaapkamer",
"preset_modes": ["home", "asleep", "away", "vacation", "no_frost"],
Expand Down
16 changes: 6 additions & 10 deletions tests/components/plugwise/fixtures/m_adam_cooling/all_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,20 @@
"available_schedules": ["Weekschema", "Badkamer", "Test"],
"dev_class": "thermostat",
"location": "f2bf9048bef64cc5b6d5110154e33c81",
"mode": "heat_cool",
"mode": "cool",
"model": "ThermoTouch",
"name": "Anna",
"preset_modes": ["home", "asleep", "away", "vacation", "no_frost"],
"select_schedule": "Weekschema",
"selected_schedule": "None",
"sensors": {
"setpoint_high": 23.5,
"setpoint_low": 4.0,
"setpoint": 23.5,
"temperature": 25.8
},
"thermostat": {
"lower_bound": 1.0,
"resolution": 0.01,
"setpoint_high": 23.5,
"setpoint_low": 4.0,
"setpoint": 23.5,
"upper_bound": 35.0
},
"vendor": "Plugwise"
Expand Down Expand Up @@ -115,9 +113,8 @@
"select_schedule": "Badkamer",
"sensors": {
"battery": 56,
"setpoint_high": 23.5,
"setpoint_low": 20.0,
"temperature": 239
"setpoint": 23.5,
"temperature": 23.9
},
"temperature_offset": {
"lower_bound": -2.0,
Expand All @@ -128,8 +125,7 @@
"thermostat": {
"lower_bound": 0.0,
"resolution": 0.01,
"setpoint_high": 25.0,
"setpoint_low": 19.0,
"setpoint": 25.0,
"upper_bound": 99.9
},
"vendor": "Plugwise",
Expand Down