From ad986b0c3b27f22e558426988fb1375ce9ee1228 Mon Sep 17 00:00:00 2001 From: Thomas Germain <12560542+thomasgermain@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:31:29 +0100 Subject: [PATCH] ha 2022.11 compatibility +set_datetime service (#162) ha 2022.11 compatibility +set_datetime service --- README.md | 1 + custom_components/multimatic/const.py | 3 +- custom_components/multimatic/coordinator.py | 10 ++- custom_components/multimatic/manifest.json | 8 +-- custom_components/multimatic/sensor.py | 6 +- custom_components/multimatic/service.py | 16 +++++ custom_components/multimatic/services.yaml | 70 ++++++++++++++++++++- hacs.json | 2 +- 8 files changed, 102 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 720ab05..49f6607 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ For the `binary_sensor.multimtic_holiday`, when on, you have the start date, end - `multimatic.request_hvac_update` to tell multimatic API to fetch data from your installation and made them available in the API - `multimatic.set_ventilation_day_level` to set ventilation day level - `multimatic.set_ventilation_night_level` to set ventilation night level +- `multimatic.set_datetime` to set the current date time of the system This will allow you to create some buttons in UI to activate/deactivate quick mode or holiday mode with a single click diff --git a/custom_components/multimatic/const.py b/custom_components/multimatic/const.py index 78decc1..ce63f53 100644 --- a/custom_components/multimatic/const.py +++ b/custom_components/multimatic/const.py @@ -42,6 +42,7 @@ ATTR_TEMPERATURE = "temperature" ATTR_DURATION = "duration" ATTR_LEVEL = "level" +ATTR_DATE_TIME = "datetime" SERVICES_HANDLER = "services_handler" @@ -73,5 +74,5 @@ HVAC_STATUS: None, FACILITY_DETAIL: timedelta(days=1), GATEWAY: timedelta(days=1), - EMF_REPORTS: timedelta(minutes=30), + EMF_REPORTS: None, } diff --git a/custom_components/multimatic/coordinator.py b/custom_components/multimatic/coordinator.py index 8ca9ce4..e4c146d 100644 --- a/custom_components/multimatic/coordinator.py +++ b/custom_components/multimatic/coordinator.py @@ -394,6 +394,10 @@ async def set_fan_night_level(self, entity, level): """Set fan night level.""" await self._manager.set_ventilation_night_level(entity.component.id, level) + async def set_datetime(self, datetime): + """Set datetime.""" + await self._manager.set_datetime(datetime) + async def _remove_quick_mode_no_refresh(self, entity=None): removed = False @@ -413,7 +417,7 @@ async def _hard_remove_quick_mode(self): self._quick_mode = None async def _hard_set_quick_mode( - self, mode: str | QuickMode, duration: int = None + self, mode: str | QuickMode, duration: int | None = None ) -> QuickMode: new_mode: QuickMode @@ -489,8 +493,8 @@ def __init__( def find_component( self, comp_id - ) -> Room | Zone | Ventilation | HotWater | Circulation: - """Find component by it's id.""" + ) -> Room | Zone | Ventilation | HotWater | Circulation | None: + """Find component by its id.""" for comp in self.data: if comp.id == comp_id: return comp diff --git a/custom_components/multimatic/manifest.json b/custom_components/multimatic/manifest.json index c5d8457..c2e4f25 100644 --- a/custom_components/multimatic/manifest.json +++ b/custom_components/multimatic/manifest.json @@ -5,15 +5,13 @@ "documentation": "https://github.com/thomasgermain/vaillant-component", "issue_tracker": "https://github.com/thomasgermain/vaillant-component/issues", "requirements": [ - "pymultimatic==0.6.8" + "pymultimatic==0.6.10" ], "ssdp": [], "zeroconf": [], "homekit": {}, "dependencies": [], - "codeowners": [ - "@thomasgermain" - ], - "version": "1.12.7", + "codeowners": ["@thomasgermain"], + "version": "1.12.9", "iot_class": "cloud_polling" } diff --git a/custom_components/multimatic/sensor.py b/custom_components/multimatic/sensor.py index 9581bff..4a654c0 100644 --- a/custom_components/multimatic/sensor.py +++ b/custom_components/multimatic/sensor.py @@ -12,7 +12,7 @@ SensorEntity, SensorStateClass, ) -from homeassistant.const import ENERGY_WATT_HOUR, TEMP_CELSIUS +from homeassistant.const import UnitOfEnergy, UnitOfTemperature from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.typing import StateType @@ -75,7 +75,7 @@ def available(self): @property def native_unit_of_measurement(self) -> str | None: """Return the unit of measurement of this entity, if any.""" - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS @property def name(self) -> str: @@ -204,7 +204,7 @@ def available(self): @property def native_unit_of_measurement(self) -> str | None: """Return the unit of measurement of this entity, if any.""" - return ENERGY_WATT_HOUR + return UnitOfEnergy.WATT_HOUR @property def device_info(self): diff --git a/custom_components/multimatic/service.py b/custom_components/multimatic/service.py index 682fbbc..8cfa4a9 100644 --- a/custom_components/multimatic/service.py +++ b/custom_components/multimatic/service.py @@ -1,13 +1,16 @@ """multimatic services.""" +import datetime import logging from pymultimatic.model import QuickMode, QuickModes import voluptuous as vol from homeassistant.const import ATTR_ENTITY_ID +import homeassistant.helpers.config_validation as cv from homeassistant.util.dt import parse_date from .const import ( + ATTR_DATE_TIME, ATTR_DURATION, ATTR_END_DATE, ATTR_LEVEL, @@ -32,6 +35,7 @@ SERVICE_REQUEST_HVAC_UPDATE = "request_hvac_update" SERVICE_SET_VENTILATION_DAY_LEVEL = "set_ventilation_day_level" SERVICE_SET_VENTILATION_NIGHT_LEVEL = "set_ventilation_night_level" +SERVICE_SET_DATETIME = "set_datetime" SERVICE_REMOVE_QUICK_MODE_SCHEMA = vol.Schema({}) SERVICE_REMOVE_HOLIDAY_MODE_SCHEMA = vol.Schema({}) @@ -77,6 +81,12 @@ SERVICE_SET_VENTILATION_NIGHT_LEVEL_SCHEMA = SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA +SERVICE_SET_DATETIME_SCHEMA = vol.Schema( + { + vol.Optional(ATTR_DATE_TIME): cv.datetime, + } +) + SERVICES = { SERVICE_REMOVE_QUICK_MODE: { "schema": SERVICE_REMOVE_QUICK_MODE_SCHEMA, @@ -106,6 +116,7 @@ "schema": SERVICE_SET_VENTILATION_DAY_LEVEL_SCHEMA, "entity": True, }, + SERVICE_SET_DATETIME: {"schema": SERVICE_SET_DATETIME_SCHEMA}, } @@ -151,3 +162,8 @@ 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_datetime(self, data): + """Set date time.""" + date_t: datetime = data.get(ATTR_DATE_TIME, datetime.datetime.now()) + await self.api.set_datetime(date_t) diff --git a/custom_components/multimatic/services.yaml b/custom_components/multimatic/services.yaml index 340f7e1..bb58cfd 100644 --- a/custom_components/multimatic/services.yaml +++ b/custom_components/multimatic/services.yaml @@ -10,9 +10,23 @@ set_quick_mode: quick_mode: description: Name of the quick mode (required) example: QM_HOTWATER_BOOST, QM_VENTILATION_BOOST, QM_ONE_DAY_AWAY, QM_SYSTEM_OFF, QM_ONE_DAY_AT_HOME, QM_PARTY + selector: + select: + options: + - QM_HOTWATER_BOOST + - QM_VENTILATION_BOOST + - QM_ONE_DAY_AWAY + - QM_SYSTEM_OFF + - QM_ONE_DAY_AT_HOME + - QM_PARTY duration: description: (int) number of days the quick mode should last example: 3 + selector: + number: + min: 0 + max: 7 + mode: box set_holiday_mode: description: Set holiday mode @@ -20,12 +34,21 @@ set_holiday_mode: start_date: description: Start date of the holiday mode YYYY-MM-DD format (required) example: "2019-11-25" + selector: + date: end_date: description: End date of the holiday mode, YYYY-MM-DD format (required) example: "2019-11-26" + selector: + date: temperature: description: temperature to maintin while holiday mode is active (required) example: 15 + selector: + number: + min: 5 + max: 30 + mode: box set_quick_veto: description: Set a quick veto for a climate entity @@ -33,12 +56,26 @@ set_quick_veto: entity_id: description: Entity id from where to set a quick veto example: climate.bathroom + selector: + entity: + integration: multimatic + domain: climate temperature: description: Target temperature to be applied while quick veto is running on example: 25 + selector: + number: + min: 5 + max: 30 + mode: box duration: description: Duration (in minutes) of the quick veto. Min 30min, max 1440 (24 hours). If not specified, the default (configured) duration is applied. - example: "60" + example: 60 + selector: + number: + min: 30 + max: 1440 + mode: box remove_quick_veto: description: Remove a quick veto for a climate entity @@ -46,6 +83,10 @@ remove_quick_veto: entity_id: description: Entity id from where to remove quick veto example: climate.bathroom + selector: + entity: + integration: multimatic + domain: climate request_hvac_update: description: Ask multimatic API to get data from your installation. @@ -56,9 +97,18 @@ set_ventilation_day_level: entity_id: description: Entity id of the fan example: fan.bathroom + selector: + entity: + integration: multimatic + domain: fan level: description: Level to set (required) example: 1 + selector: + number: + min: 1 + max: 7 + mode: box set_ventilation_night_level: description: Set night level ventilation @@ -66,6 +116,24 @@ set_ventilation_night_level: entity_id: description: Entity id of the fan example: fan.bathroom + selector: + entity: + integration: multimatic + domain: fan level: description: Level to set (required) example: 2 + selector: + number: + min: 1 + max: 7 + mode: box + +set_datetime: + description: Set multimatic system datetime + fields: + datetime: + description: datetime to set + example: 2022-11-06T11:11:38 + selector: + datetime: diff --git a/hacs.json b/hacs.json index 8ca0d35..40bc1ac 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { "name": "multimatic", "render_readme": true, - "homeassistant": "2022.5.0" + "homeassistant": "2022.11.0" }