diff --git a/custom_components/multimatic/binary_sensor.py b/custom_components/multimatic/binary_sensor.py index a773344..b1c9810 100644 --- a/custom_components/multimatic/binary_sensor.py +++ b/custom_components/multimatic/binary_sensor.py @@ -6,12 +6,8 @@ from pymultimatic.model import Device, OperatingModes, QuickModes, Room, SettingModes from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_CONNECTIVITY, - DEVICE_CLASS_LOCK, - DEVICE_CLASS_PROBLEM, - DEVICE_CLASS_WINDOW, DOMAIN, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC @@ -124,7 +120,9 @@ class RoomWindow(MultimaticEntity, BinarySensorEntity): def __init__(self, coordinator: MultimaticCoordinator, room: Room) -> None: """Initialize entity.""" - super().__init__(coordinator, DOMAIN, f"{room.name}_{DEVICE_CLASS_WINDOW}") + super().__init__( + coordinator, DOMAIN, f"{room.name}_{BinarySensorDeviceClass.WINDOW}" + ) self._room_id = room.id @property @@ -140,7 +138,7 @@ def available(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_WINDOW + return BinarySensorDeviceClass.WINDOW @property def name(self) -> str: @@ -182,7 +180,7 @@ def device_info(self): } @property - def device_state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" device = self.device return { @@ -222,7 +220,7 @@ def __init__( self, coordinator: MultimaticCoordinator, device: Device, room: Room ) -> None: """Initialize entity.""" - super().__init__(coordinator, device, DEVICE_CLASS_LOCK) + super().__init__(coordinator, device, BinarySensorDeviceClass.LOCK) self._room_id = room.id @property @@ -243,7 +241,7 @@ def room(self) -> Room: @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_LOCK + return BinarySensorDeviceClass.LOCK @property def entity_category(self) -> str | None: @@ -256,7 +254,7 @@ class RoomDeviceBattery(RoomDeviceEntity): def __init__(self, coordinator: MultimaticCoordinator, device: Device) -> None: """Initialize entity.""" - super().__init__(coordinator, device, DEVICE_CLASS_BATTERY) + super().__init__(coordinator, device, BinarySensorDeviceClass.BATTERY) @property def is_on(self): @@ -266,7 +264,7 @@ def is_on(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_BATTERY + return BinarySensorDeviceClass.BATTERY @property def entity_category(self) -> str | None: @@ -279,7 +277,7 @@ class RoomDeviceConnectivity(RoomDeviceEntity): def __init__(self, coordinator: MultimaticCoordinator, device: Device) -> None: """Initialize entity.""" - super().__init__(coordinator, device, DEVICE_CLASS_CONNECTIVITY) + super().__init__(coordinator, device, BinarySensorDeviceClass.CONNECTIVITY) @property def is_on(self): @@ -289,7 +287,7 @@ def is_on(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_CONNECTIVITY + return BinarySensorDeviceClass.CONNECTIVITY @property def entity_category(self) -> str | None: @@ -385,7 +383,7 @@ def name(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_CONNECTIVITY + return BinarySensorDeviceClass.CONNECTIVITY @property def entity_category(self) -> str | None: @@ -433,7 +431,7 @@ def device_info(self): } @property - def device_state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" if self.available: return {"device_id": self._boiler_id, "error": self.boiler_status.is_error} @@ -457,7 +455,7 @@ def boiler_status(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_PROBLEM + return BinarySensorDeviceClass.PROBLEM @property def entity_category(self) -> str | None: @@ -479,7 +477,10 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None: @property def is_on(self): """Return true if the binary sensor is on.""" - return self.coordinator.data.errors and len(self.coordinator.data.errors) > 0 + if self.coordinator.data.errors: + return len(self.coordinator.data.errors) > 0 + else: + return False @property def state_attributes(self): @@ -503,7 +504,7 @@ def state_attributes(self): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_PROBLEM + return BinarySensorDeviceClass.PROBLEM @property def name(self): @@ -564,7 +565,7 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None: @property def is_on(self): """Return true if the binary sensor is on.""" - return self.coordinator.data + return False if self.coordinator.data is None else True @property def state_attributes(self): diff --git a/custom_components/multimatic/coordinator.py b/custom_components/multimatic/coordinator.py index da550be..8122ff3 100644 --- a/custom_components/multimatic/coordinator.py +++ b/custom_components/multimatic/coordinator.py @@ -390,13 +390,13 @@ async def set_fan_operating_mode(self, entity, mode: Mode): entity.component.operating_mode = mode await self._refresh(touch_system, entity) - async def set_fan_day_level(self, level): + async def set_fan_day_level(self, entity, level): """Set fan day level.""" - await self._manager.set_ventilation_day_level(level) + await self._manager.set_ventilation_day_level(entity.component.id, level) - async def set_fan_night_level(self, level): + async def set_fan_night_level(self, entity, level): """Set fan night level.""" - await self._manager.set_ventilation_night_level(level) + await self._manager.set_ventilation_night_level(entity.component.id, level) async def _remove_quick_mode_no_refresh(self, entity=None): removed = False @@ -530,6 +530,7 @@ async def _first_fetch_data(self): self.name, exc_info=True, ) + return None else: raise diff --git a/custom_components/multimatic/fan.py b/custom_components/multimatic/fan.py index 2612384..5d92291 100644 --- a/custom_components/multimatic/fan.py +++ b/custom_components/multimatic/fan.py @@ -10,7 +10,7 @@ from homeassistant.components.fan import DOMAIN, SUPPORT_PRESET_MODE, FanEntity from homeassistant.helpers import entity_platform -from .const import VENTILATION +from .const import ATTR_LEVEL, VENTILATION from .coordinator import MultimaticCoordinator from .entities import MultimaticEntity from .service import ( @@ -136,3 +136,11 @@ def available(self): def active_mode(self): """Return the active mode.""" return self.coordinator.api.get_active_mode(self.component) + + async def set_ventilation_day_level(self, **kwargs): + """Service method to set day level.""" + await self.coordinator.api.set_fan_day_level(self, kwargs.get(ATTR_LEVEL)) + + async def set_ventilation_night_level(self, **kwargs): + """Service method to set night level.""" + await self.coordinator.api.set_fan_night_level(self, kwargs.get(ATTR_LEVEL)) diff --git a/custom_components/multimatic/manifest.json b/custom_components/multimatic/manifest.json index f4df5a6..893e1d1 100644 --- a/custom_components/multimatic/manifest.json +++ b/custom_components/multimatic/manifest.json @@ -5,7 +5,7 @@ "documentation": "https://github.com/thomasgermain/vaillant-component", "issue_tracker": "https://github.com/thomasgermain/vaillant-component/issues", "requirements": [ - "pymultimatic==0.6.5" + "pymultimatic==0.6.6" ], "ssdp": [], "zeroconf": [], @@ -14,6 +14,6 @@ "codeowners": [ "@thomasgermain" ], - "version": "1.11.0", + "version": "1.12.0", "iot_class": "cloud_polling" } diff --git a/custom_components/multimatic/sensor.py b/custom_components/multimatic/sensor.py index b114a78..7d298de 100644 --- a/custom_components/multimatic/sensor.py +++ b/custom_components/multimatic/sensor.py @@ -8,12 +8,10 @@ from pymultimatic.model import EmfReport, Report from homeassistant.components.sensor import ( - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_PRESSURE, - DEVICE_CLASS_TEMPERATURE, DOMAIN, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, ) from homeassistant.const import ( @@ -32,9 +30,9 @@ _LOGGER = logging.getLogger(__name__) UNIT_TO_DEVICE_CLASS = { - "bar": DEVICE_CLASS_PRESSURE, + "bar": SensorDeviceClass.PRESSURE, "ppm": "", - "°C": DEVICE_CLASS_TEMPERATURE, + "°C": SensorDeviceClass.TEMPERATURE, } @@ -92,7 +90,7 @@ def name(self) -> str: @property def device_class(self) -> str: """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_TEMPERATURE + return SensorDeviceClass.TEMPERATURE @property def state_class(self) -> str | None: @@ -226,7 +224,7 @@ def device_info(self): @property def device_class(self) -> str | None: """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_ENERGY + return SensorDeviceClass.ENERGY @property def name(self) -> str | None: diff --git a/custom_components/multimatic/service.py b/custom_components/multimatic/service.py index 9b9efff..682fbbc 100644 --- a/custom_components/multimatic/service.py +++ b/custom_components/multimatic/service.py @@ -70,6 +70,7 @@ SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA = vol.Schema( { + vol.Required(ATTR_ENTITY_ID): vol.All(vol.Coerce(str)), vol.Required(ATTR_LEVEL): vol.All(vol.Coerce(int), vol.Clamp(min=1, max=6)), } ) @@ -98,10 +99,12 @@ "schema": SERVICE_REQUEST_HVAC_UPDATE_SCHEMA, }, SERVICE_SET_VENTILATION_NIGHT_LEVEL: { - "schema": SERVICE_SET_VENTILATION_NIGHT_LEVEL_SCHEMA + "schema": SERVICE_SET_VENTILATION_NIGHT_LEVEL_SCHEMA, + "entity": True, }, SERVICE_SET_VENTILATION_DAY_LEVEL: { - "schema": SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA + "schema": SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA, + "entity": True, }, } @@ -148,11 +151,3 @@ async def set_quick_mode(self, data): async def request_hvac_update(self, data): """Ask multimatic API to get data from the installation.""" await self.api.request_hvac_update() - - async def set_ventilation_day_level(self, data): - """Set ventilation day level.""" - await self.api.set_fan_day_level(data.get(ATTR_LEVEL)) - - async def set_ventilation_night_level(self, data): - """Set ventilation day level.""" - await self.api.set_fan_night_level(data.get(ATTR_LEVEL)) diff --git a/custom_components/multimatic/services.yaml b/custom_components/multimatic/services.yaml index 1b3c870..340f7e1 100644 --- a/custom_components/multimatic/services.yaml +++ b/custom_components/multimatic/services.yaml @@ -49,3 +49,23 @@ remove_quick_veto: request_hvac_update: description: Ask multimatic API to get data from your installation. + +set_ventilation_day_level: + description: Set day level ventilation + fields: + entity_id: + description: Entity id of the fan + example: fan.bathroom + level: + description: Level to set (required) + example: 1 + +set_ventilation_night_level: + description: Set night level ventilation + fields: + entity_id: + description: Entity id of the fan + example: fan.bathroom + level: + description: Level to set (required) + example: 2 diff --git a/hacs.json b/hacs.json index 103a204..d2df0c7 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": "2021.11.0" + "homeassistant": "2021.12.0" }