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

Commit

Permalink
ha 2023.1 compatibility (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasgermain authored Dec 31, 2022
1 parent 8c59687 commit 11bec7a
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 165 deletions.
137 changes: 73 additions & 64 deletions custom_components/multimatic/binary_sensor.py

Large diffs are not rendered by default.

76 changes: 39 additions & 37 deletions custom_components/multimatic/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
)

from homeassistant.components.climate import (
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.components.climate.const import (
DOMAIN,
PRESET_AWAY,
PRESET_COMFORT,
PRESET_HOME,
PRESET_NONE,
PRESET_SLEEP,
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import SERVICES
from .const import (
Expand Down Expand Up @@ -64,9 +66,11 @@
}


async def async_setup_entry(hass, entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the multimatic climate platform."""
climates = []
climates: list[MultimaticClimate] = []
zones_coo = get_coordinator(hass, ZONES, entry.unique_id)
rooms_coo = get_coordinator(hass, ROOMS, entry.unique_id)
ventilation_coo = get_coordinator(hass, VENTILATION, entry.unique_id)
Expand All @@ -86,7 +90,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities(climates)

if len(climates) > 0:
platform = entity_platform.current_platform.get()
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_REMOVE_QUICK_VETO,
SERVICES[SERVICE_REMOVE_QUICK_VETO]["schema"],
Expand All @@ -98,8 +102,6 @@ async def async_setup_entry(hass, entry, async_add_entities):
SERVICE_SET_QUICK_VETO,
)

return True


class MultimaticClimate(MultimaticEntity, ClimateEntity, abc.ABC):
"""Base class for climate."""
Expand Down Expand Up @@ -134,22 +136,22 @@ def component(self) -> Component:
"""Return the room or the zone."""

@property
def available(self):
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self.component

@property
def temperature_unit(self):
def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def target_temperature(self):
def target_temperature(self) -> float:
"""Return the temperature we try to reach."""
return self.active_mode.target

@property
def current_temperature(self):
def current_temperature(self) -> float:
"""Return the current temperature."""
return self.component.temperature

Expand Down Expand Up @@ -244,17 +246,17 @@ def __init__(
self._zone_coo = zone_coo

@property
def device_info(self):
def device_info(self) -> DeviceInfo | None:
"""Return device specific attributes."""
devices = self.component.devices
if len(devices) == 1: # Can't link an entity to multiple devices
return {
"identifiers": {(MULTIMATIC, devices[0].sgtin)},
"name": devices[0].name,
"manufacturer": "Vaillant",
"model": devices[0].device_type,
}
return {}
return DeviceInfo(
identifiers={(MULTIMATIC, devices[0].sgtin)},
name=devices[0].name,
manufacturer="Vaillant",
model=devices[0].device_type,
)
return None

@property
def component(self) -> Room:
Expand All @@ -280,19 +282,19 @@ def hvac_modes(self) -> list[HVACMode]:
return self._supported_hvac

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

@property
def min_temp(self):
def min_temp(self) -> float:
"""Return the minimum temperature."""
return Room.MIN_TARGET_TEMP

@property
def max_temp(self):
def max_temp(self) -> float:
"""Return the maximum temperature."""
return Room.MAX_TARGET_TEMP

Expand All @@ -305,10 +307,10 @@ def zone(self):
)
return None

async def async_set_temperature(self, **kwargs):
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
await self.coordinator.api.set_room_target_temperature(
self, float(kwargs.get(ATTR_TEMPERATURE))
self, kwargs.get(ATTR_TEMPERATURE)
)

async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
Expand Down Expand Up @@ -433,7 +435,7 @@ def component(self) -> Zone:
return self.coordinator.find_component(self._zone_id)

@property
def hvac_mode(self):
def hvac_mode(self) -> HVACMode:
"""Get the hvac mode based on multimatic mode."""
current_mode = self.active_mode.current
hvac_mode = ZoneClimate._MULTIMATIC_TO_HA[current_mode][0]
Expand Down Expand Up @@ -462,28 +464,28 @@ def hvac_modes(self) -> list[HVACMode]:
return self._supported_hvac

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

@property
def min_temp(self):
def min_temp(self) -> float:
"""Return the minimum temperature."""
return Zone.MIN_TARGET_HEATING_TEMP

@property
def max_temp(self):
def max_temp(self) -> float:
"""Return the maximum temperature."""
return Zone.MAX_TARGET_TEMP

@property
def target_temperature(self):
def target_temperature(self) -> float:
"""Return the temperature we try to reach."""
return self.active_mode.target

async def async_set_temperature(self, **kwargs):
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
temp = kwargs.get(ATTR_TEMPERATURE)

Expand All @@ -493,7 +495,7 @@ async def async_set_temperature(self, **kwargs):
else:
_LOGGER.debug("Nothing to do")

async def async_set_hvac_mode(self, hvac_mode):
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
mode = ZoneClimate._HA_MODE_TO_MULTIMATIC[hvac_mode]
await self.coordinator.api.set_zone_operating_mode(self, mode)
Expand Down
8 changes: 5 additions & 3 deletions custom_components/multimatic/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import voluptuous as vol

from homeassistant import config_entries, core, exceptions
from homeassistant.config_entries import ConfigEntry, OptionsFlow
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_create_clientsession
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -60,11 +62,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

@staticmethod
@callback
def async_get_options_flow(config_entry):
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow:
"""Get the options flow for this handler."""
return MultimaticOptionsFlowHandler(config_entry)

async def async_step_user(self, user_input=None):
async def async_step_user(self, user_input=None) -> FlowResult:
"""Handle the initial step."""
errors = {}
if user_input is not None:
Expand Down Expand Up @@ -92,7 +94,7 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry

async def async_step_init(self, user_input=None):
async def async_step_init(self, user_input=None) -> FlowResult:
"""Handle options flow."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
Expand Down
19 changes: 12 additions & 7 deletions custom_components/multimatic/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from pymultimatic.model import OperatingModes, QuickModes

from homeassistant.components.fan import DOMAIN, FanEntity, FanEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import ATTR_LEVEL, VENTILATION
from .coordinator import MultimaticCoordinator
Expand All @@ -24,7 +27,9 @@
_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the multimatic fan platform."""

coordinator = get_coordinator(hass, VENTILATION, entry.unique_id)
Expand All @@ -34,7 +39,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
async_add_entities([MultimaticFan(coordinator)])

_LOGGER.debug("Adding fan services")
platform = entity_platform.current_platform.get()
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_VENTILATION_DAY_LEVEL,
SERVICES[SERVICE_SET_VENTILATION_DAY_LEVEL]["schema"],
Expand Down Expand Up @@ -85,7 +90,7 @@ async def async_turn_on(
self,
percentage: int | None = None,
preset_mode: str | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Turn on the fan."""
if preset_mode:
Expand All @@ -94,19 +99,19 @@ async def async_turn_on(
mode = OperatingModes.AUTO
return await self.coordinator.api.set_fan_operating_mode(self, mode)

async def async_turn_off(self, **kwargs: Any):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn on the fan."""
return await self.coordinator.api.set_fan_operating_mode(
self, OperatingModes.NIGHT
)

@property
def is_on(self):
def is_on(self) -> bool:
"""Return true if the entity is on."""
return self.active_mode.current != OperatingModes.NIGHT

@property
def supported_features(self) -> int:
def supported_features(self) -> FanEntityFeature:
"""Flag supported features."""
return FanEntityFeature.PRESET_MODE

Expand All @@ -126,7 +131,7 @@ def preset_modes(self) -> list[str] | None:
return self._preset_modes

@property
def available(self):
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self.component

Expand Down
4 changes: 2 additions & 2 deletions custom_components/multimatic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"documentation": "https://github.com/thomasgermain/vaillant-component",
"issue_tracker": "https://github.com/thomasgermain/vaillant-component/issues",
"requirements": [
"pymultimatic==0.6.11"
"pymultimatic==0.6.12"
],
"ssdp": [],
"zeroconf": [],
"homekit": {},
"dependencies": [],
"codeowners": ["@thomasgermain"],
"version": "1.12.11",
"version": "1.12.12",
"iot_class": "cloud_polling"
}
Loading

0 comments on commit 11bec7a

Please sign in to comment.