diff --git a/custom_components/multimatic/__init__.py b/custom_components/multimatic/__init__.py index 56c12b2..83b7de7 100644 --- a/custom_components/multimatic/__init__.py +++ b/custom_components/multimatic/__init__.py @@ -6,6 +6,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant +from homeassistant.helpers.typing import ConfigType from .const import ( COORDINATOR_LIST, @@ -21,12 +22,12 @@ _LOGGER = logging.getLogger(__name__) -async def async_setup(hass: HomeAssistant, config: dict): +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the multimatic integration.""" return True -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): +async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up multimatic from a config entry.""" api: MultimaticApi = MultimaticApi(hass, entry) @@ -90,7 +91,7 @@ async def async_unload_services(hass): hass.services.async_remove(DOMAIN, service_name) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload_ok = all( await asyncio.gather( diff --git a/custom_components/multimatic/binary_sensor.py b/custom_components/multimatic/binary_sensor.py index 8e97443..e2f4ea2 100644 --- a/custom_components/multimatic/binary_sensor.py +++ b/custom_components/multimatic/binary_sensor.py @@ -10,8 +10,8 @@ BinarySensorDeviceClass, BinarySensorEntity, ) -from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC +from homeassistant.helpers.entity import EntityCategory from homeassistant.util import slugify from .const import ( @@ -110,12 +110,12 @@ def name(self) -> str: return self.coordinator.data.circulation.name @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.RUNNING @@ -141,7 +141,7 @@ def available(self): return super().available and self.room @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.WINDOW @@ -156,9 +156,9 @@ def room(self) -> Room: return self.coordinator.find_component(self._room_id) @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class RoomDeviceEntity(MultimaticEntity, BinarySensorEntity): @@ -244,14 +244,14 @@ def room(self) -> Room: return self.coordinator.find_component(self._room_id) @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.LOCK @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class RoomDeviceBattery(RoomDeviceEntity): @@ -267,14 +267,14 @@ def is_on(self): return self.device.battery_low @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.BATTERY @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class RoomDeviceConnectivity(RoomDeviceEntity): @@ -290,14 +290,14 @@ def is_on(self): return not self.device.radio_out_of_reach @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.CONNECTIVITY @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class VRBoxEntity(MultimaticEntity, BinarySensorEntity): @@ -358,12 +358,12 @@ def name(self) -> str | None: return "Multimatic system update" @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.UPDATE @@ -391,14 +391,14 @@ def name(self): return "Multimatic system Online" @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.CONNECTIVITY @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class BoilerStatus(MultimaticEntity, BinarySensorEntity): @@ -463,14 +463,14 @@ def boiler_status(self): return self.coordinator.data.boiler_status if self.coordinator.data else None @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.PROBLEM @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class MultimaticErrors(MultimaticEntity, BinarySensorEntity): @@ -489,8 +489,7 @@ def is_on(self): """Return true if the binary sensor is on.""" if self.coordinator.data.errors: return len(self.coordinator.data.errors) > 0 - else: - return False + return False @property def state_attributes(self): @@ -512,7 +511,7 @@ def state_attributes(self): return state_attributes @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.PROBLEM @@ -522,9 +521,9 @@ def name(self): return "Multimatic Errors" @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class HolidayModeSensor(MultimaticEntity, BinarySensorEntity): @@ -560,12 +559,12 @@ def available(self) -> bool: return self.coordinator.last_update_success @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.OCCUPANCY @@ -603,11 +602,11 @@ def available(self) -> bool: return self.coordinator.last_update_success @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC @property - def device_class(self): + def device_class(self) -> BinarySensorDeviceClass | str | None: """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.RUNNING diff --git a/custom_components/multimatic/coordinator.py b/custom_components/multimatic/coordinator.py index 8122ff3..a291e7b 100644 --- a/custom_components/multimatic/coordinator.py +++ b/custom_components/multimatic/coordinator.py @@ -531,8 +531,7 @@ async def _first_fetch_data(self): exc_info=True, ) return None - else: - raise + raise async def _safe_logout(self): try: diff --git a/custom_components/multimatic/fan.py b/custom_components/multimatic/fan.py index 974859e..d5d1f7d 100644 --- a/custom_components/multimatic/fan.py +++ b/custom_components/multimatic/fan.py @@ -7,12 +7,7 @@ from pymultimatic.model import OperatingModes, QuickModes -from homeassistant.components.fan import ( - DOMAIN, - SUPPORT_PRESET_MODE, - FanEntity, - ATTR_SPEED, -) +from homeassistant.components.fan import DOMAIN, SUPPORT_PRESET_MODE, FanEntity from homeassistant.helpers import entity_platform from .const import ATTR_LEVEL, VENTILATION @@ -87,7 +82,6 @@ async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_turn_on( self, - speed: str | None = None, percentage: int | None = None, preset_mode: str | None = None, **kwargs, @@ -95,8 +89,6 @@ async def async_turn_on( """Turn on the fan.""" if preset_mode: mode = OperatingModes.get(preset_mode.upper()) - elif speed: - mode = OperatingModes.get(speed.upper()) else: mode = OperatingModes.AUTO return await self.coordinator.api.set_fan_operating_mode(self, mode) @@ -153,4 +145,4 @@ async def set_ventilation_night_level(self, **kwargs): @property def extra_state_attributes(self) -> Mapping[str, Any] | None: """Return entity specific state attributes.""" - return {ATTR_SPEED: self.active_mode.target} + return {"speed": self.active_mode.target} diff --git a/custom_components/multimatic/manifest.json b/custom_components/multimatic/manifest.json index a266c36..1f80eed 100644 --- a/custom_components/multimatic/manifest.json +++ b/custom_components/multimatic/manifest.json @@ -14,6 +14,6 @@ "codeowners": [ "@thomasgermain" ], - "version": "1.12.3", + "version": "1.12.4", "iot_class": "cloud_polling" } diff --git a/custom_components/multimatic/sensor.py b/custom_components/multimatic/sensor.py index 273398e..9581bff 100644 --- a/custom_components/multimatic/sensor.py +++ b/custom_components/multimatic/sensor.py @@ -8,16 +8,12 @@ from homeassistant.components.sensor import ( DOMAIN, - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, SensorDeviceClass, SensorEntity, + SensorStateClass, ) -from homeassistant.const import ( - ENERGY_WATT_HOUR, - ENTITY_CATEGORY_DIAGNOSTIC, - TEMP_CELSIUS, -) +from homeassistant.const import ENERGY_WATT_HOUR, TEMP_CELSIUS +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.typing import StateType from .const import EMF_REPORTS, OUTDOOR_TEMP, REPORTS @@ -94,12 +90,12 @@ def device_class(self) -> str: @property def state_class(self) -> str | None: """Return the state class of this entity.""" - return STATE_CLASS_MEASUREMENT + return SensorStateClass.MEASUREMENT @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class ReportSensor(MultimaticEntity, SensorEntity): @@ -155,7 +151,7 @@ def device_info(self): @property def state_class(self) -> str | None: """Return the state class of this entity, from STATE_CLASSES, if any.""" - return STATE_CLASS_MEASUREMENT + return SensorStateClass.MEASUREMENT @property def device_class(self) -> str | None: @@ -168,9 +164,9 @@ def name(self) -> str | None: return self._name @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC class EmfReportSensor(MultimaticEntity, SensorEntity): @@ -233,9 +229,9 @@ def name(self) -> str | None: @property def state_class(self) -> str: """Return the state class of this entity.""" - return STATE_CLASS_TOTAL_INCREASING + return SensorStateClass.TOTAL_INCREASING @property - def entity_category(self) -> str | None: + def entity_category(self) -> EntityCategory | None: """Return the category of the entity, if any.""" - return ENTITY_CATEGORY_DIAGNOSTIC + return EntityCategory.DIAGNOSTIC diff --git a/hacs.json b/hacs.json index ab7e518..7e182d1 100644 --- a/hacs.json +++ b/hacs.json @@ -2,5 +2,5 @@ "name": "multimatic", "domains": ["binary_sensor", "climate", "fan", "sensor", "water_heater"], "render_readme": true, - "homeassistant": "2022.02.0" + "homeassistant": "2022.04.0" }