Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
HA 2022.5 compatibility (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasgermain committed May 2, 2022
1 parent a04c4be commit 0648b31
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 56 deletions.
2 changes: 1 addition & 1 deletion custom_components/multimatic/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None:
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return False if self.coordinator.data is None else True
return self.coordinator.data is not None

@property
def state_attributes(self):
Expand Down
92 changes: 46 additions & 46 deletions custom_components/multimatic/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from __future__ import annotations

import abc
from collections.abc import Mapping
import logging
from typing import Any, Mapping
from typing import Any

from pymultimatic.model import (
ActiveFunction,
Expand All @@ -16,24 +17,19 @@
Zone,
)

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
DOMAIN,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_COMFORT,
PRESET_HOME,
PRESET_NONE,
PRESET_SLEEP,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.helpers import entity_platform
Expand Down Expand Up @@ -62,9 +58,9 @@
_LOGGER = logging.getLogger(__name__)

_FUNCTION_TO_HVAC_ACTION: dict[ActiveFunction, str] = {
ActiveFunction.COOLING: CURRENT_HVAC_COOL,
ActiveFunction.HEATING: CURRENT_HVAC_HEAT,
ActiveFunction.STANDBY: CURRENT_HVAC_IDLE,
ActiveFunction.COOLING: HVACAction.COOLING,
ActiveFunction.HEATING: HVACAction.HEATING,
ActiveFunction.STANDBY: HVACAction.IDLE,
}


Expand Down Expand Up @@ -217,17 +213,17 @@ class RoomClimate(MultimaticClimate):
"""Climate for a room."""

_MULTIMATIC_TO_HA: dict[Mode, list] = {
OperatingModes.AUTO: [HVAC_MODE_AUTO, PRESET_COMFORT],
OperatingModes.OFF: [HVAC_MODE_OFF, PRESET_NONE],
OperatingModes.AUTO: [HVACMode.AUTO, PRESET_COMFORT],
OperatingModes.OFF: [HVACMode.OFF, PRESET_NONE],
OperatingModes.QUICK_VETO: [None, PRESET_QUICK_VETO],
QuickModes.SYSTEM_OFF: [HVAC_MODE_OFF, PRESET_SYSTEM_OFF],
QuickModes.HOLIDAY: [HVAC_MODE_OFF, PRESET_HOLIDAY],
QuickModes.SYSTEM_OFF: [HVACMode.OFF, PRESET_SYSTEM_OFF],
QuickModes.HOLIDAY: [HVACMode.OFF, PRESET_HOLIDAY],
OperatingModes.MANUAL: [None, PRESET_MANUAL],
}

_HA_MODE_TO_MULTIMATIC = {
HVAC_MODE_AUTO: OperatingModes.AUTO,
HVAC_MODE_OFF: OperatingModes.OFF,
HVACMode.AUTO: OperatingModes.AUTO,
HVACMode.OFF: OperatingModes.OFF,
}

_HA_PRESET_TO_MULTIMATIC = {
Expand Down Expand Up @@ -273,20 +269,22 @@ def hvac_mode(self) -> str:
if (
self.active_mode.current
in (OperatingModes.MANUAL, OperatingModes.QUICK_VETO)
and self.hvac_action == CURRENT_HVAC_HEAT
and self.hvac_action == HVACAction.HEATING
):
return HVAC_MODE_HEAT
return HVACMode.HEAT
return hvac_mode

@property
def hvac_modes(self) -> list[str]:
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac operation modes."""
return self._supported_hvac

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
return (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)

@property
def min_temp(self):
Expand All @@ -313,7 +311,7 @@ async def async_set_temperature(self, **kwargs):
self, float(kwargs.get(ATTR_TEMPERATURE))
)

async def async_set_hvac_mode(self, hvac_mode: str) -> None:
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
mode = RoomClimate._HA_MODE_TO_MULTIMATIC[hvac_mode]
await self.coordinator.api.set_room_operating_mode(self, mode)
Expand Down Expand Up @@ -366,26 +364,26 @@ class ZoneClimate(MultimaticClimate):
"""Climate for a zone."""

_MULTIMATIC_TO_HA: dict[Mode, list] = {
OperatingModes.AUTO: [HVAC_MODE_AUTO, PRESET_COMFORT],
OperatingModes.AUTO: [HVACMode.AUTO, PRESET_COMFORT],
OperatingModes.DAY: [None, PRESET_DAY],
OperatingModes.NIGHT: [None, PRESET_SLEEP],
OperatingModes.OFF: [HVAC_MODE_OFF, PRESET_NONE],
OperatingModes.OFF: [HVACMode.OFF, PRESET_NONE],
OperatingModes.ON: [None, PRESET_COOLING_ON],
OperatingModes.QUICK_VETO: [None, PRESET_QUICK_VETO],
QuickModes.ONE_DAY_AT_HOME: [HVAC_MODE_AUTO, PRESET_HOME],
QuickModes.ONE_DAY_AT_HOME: [HVACMode.AUTO, PRESET_HOME],
QuickModes.PARTY: [None, PRESET_PARTY],
QuickModes.VENTILATION_BOOST: [HVAC_MODE_FAN_ONLY, PRESET_NONE],
QuickModes.ONE_DAY_AWAY: [HVAC_MODE_OFF, PRESET_AWAY],
QuickModes.SYSTEM_OFF: [HVAC_MODE_OFF, PRESET_SYSTEM_OFF],
QuickModes.HOLIDAY: [HVAC_MODE_OFF, PRESET_HOLIDAY],
QuickModes.VENTILATION_BOOST: [HVACMode.FAN_ONLY, PRESET_NONE],
QuickModes.ONE_DAY_AWAY: [HVACMode.OFF, PRESET_AWAY],
QuickModes.SYSTEM_OFF: [HVACMode.OFF, PRESET_SYSTEM_OFF],
QuickModes.HOLIDAY: [HVACMode.OFF, PRESET_HOLIDAY],
QuickModes.COOLING_FOR_X_DAYS: [None, PRESET_COOLING_FOR_X_DAYS],
}

_HA_MODE_TO_MULTIMATIC = {
HVAC_MODE_AUTO: OperatingModes.AUTO,
HVAC_MODE_OFF: OperatingModes.OFF,
HVAC_MODE_FAN_ONLY: QuickModes.VENTILATION_BOOST,
HVAC_MODE_COOL: QuickModes.COOLING_FOR_X_DAYS,
HVACMode.AUTO: OperatingModes.AUTO,
HVACMode.OFF: OperatingModes.OFF,
HVACMode.FAN_ONLY: QuickModes.VENTILATION_BOOST,
HVACMode.COOL: QuickModes.COOLING_FOR_X_DAYS,
}

_HA_PRESET_TO_MULTIMATIC = {
Expand All @@ -412,10 +410,10 @@ def __init__(
if not zone.cooling:
self._supported_presets.remove(PRESET_COOLING_ON)
self._supported_presets.remove(PRESET_COOLING_FOR_X_DAYS)
self._supported_hvac.remove(HVAC_MODE_COOL)
self._supported_hvac.remove(HVACMode.COOL)

if not ventilation:
self._supported_hvac.remove(HVAC_MODE_FAN_ONLY)
self._supported_hvac.remove(HVACMode.FAN_ONLY)

self._zone_id = zone.id

Expand Down Expand Up @@ -448,25 +446,27 @@ def hvac_mode(self):
QuickModes.PARTY,
OperatingModes.QUICK_VETO,
]
and self.hvac_action == CURRENT_HVAC_HEAT
and self.hvac_action == HVACAction.HEATING
):
return HVAC_MODE_HEAT
return HVACMode.HEAT
if (
self.preset_mode in (PRESET_COOLING_ON, PRESET_COOLING_FOR_X_DAYS)
and self.hvac_action == CURRENT_HVAC_COOL
and self.hvac_action == HVACAction.COOLING
):
return HVAC_MODE_COOL
return hvac_mode if hvac_mode else HVAC_MODE_OFF
return HVACMode.COOL
return hvac_mode if hvac_mode else HVACMode.OFF

@property
def hvac_modes(self) -> list[str]:
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac operation modes."""
return self._supported_hvac

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
return (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)

@property
def min_temp(self):
Expand Down
7 changes: 4 additions & 3 deletions custom_components/multimatic/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from __future__ import annotations

from collections.abc import Mapping
import logging
from typing import Any, Mapping
from typing import Any

from pymultimatic.model import OperatingModes, QuickModes

from homeassistant.components.fan import DOMAIN, SUPPORT_PRESET_MODE, FanEntity
from homeassistant.components.fan import DOMAIN, FanEntity, FanEntityFeature
from homeassistant.helpers import entity_platform

from .const import ATTR_LEVEL, VENTILATION
Expand Down Expand Up @@ -107,7 +108,7 @@ def is_on(self):
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_PRESET_MODE
return FanEntityFeature.PRESET_MODE

@property
def preset_mode(self) -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/multimatic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"codeowners": [
"@thomasgermain"
],
"version": "1.12.5",
"version": "1.12.6",
"iot_class": "cloud_polling"
}
8 changes: 4 additions & 4 deletions custom_components/multimatic/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

from homeassistant.components.water_heater import (
DOMAIN,
SUPPORT_AWAY_MODE,
SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_TEMPERATURE,
WaterHeaterEntity,
WaterHeaterEntityFeature,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS

Expand All @@ -20,7 +18,9 @@
_LOGGER = logging.getLogger(__name__)

SUPPORTED_FLAGS = (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE | SUPPORT_AWAY_MODE
WaterHeaterEntityFeature.TARGET_TEMPERATURE
| WaterHeaterEntityFeature.OPERATION_MODE
| WaterHeaterEntityFeature.AWAY_MODE
)
ATTR_CURRENT_TEMPERATURE = "current_temperature"
ATTR_TIME_PROGRAM = "time_program"
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "multimatic",
"domains": ["binary_sensor", "climate", "fan", "sensor", "water_heater"],
"render_readme": true,
"homeassistant": "2022.4.0"
"homeassistant": "2022.5.0"
}

0 comments on commit 0648b31

Please sign in to comment.