From 1d76b467ac173fdff1636e4b8399456a3d62e5a3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 29 Oct 2023 20:42:41 +0100 Subject: [PATCH] Added water heater time program & circulation pump time program services, updated docs, changed pinning of dev requirements --- .pre-commit-config.yaml | 2 +- README.md | 2 +- custom_components/mypyllant/climate.py | 4 +- custom_components/mypyllant/const.py | 2 + custom_components/mypyllant/manifest.json | 4 +- custom_components/mypyllant/services.yaml | 69 +++++++++- custom_components/mypyllant/water_heater.py | 40 +++++- dev-requirements.txt | 31 +++-- docs/docs/1-automations.md | 144 ++++++++++++++------ docs/docs/index.md | 3 +- docs/mkdocs.yml | 5 +- 11 files changed, 242 insertions(+), 64 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c889ab9..476ec00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,7 +62,7 @@ repos: - aioresponses - pytest - types-requests - - myPyllant==0.5.11 + - myPyllant==0.5.12 - polyfactory - repo: local hooks: diff --git a/README.md b/README.md index 9f9b603..ae2a4c8 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ because of this library. * Supports climate & hot water controls, as well as sensor information * Control operating modes, target temperature, and presets such as holiday more or quick veto -* Set the schedule for climate zones with a custom service +* Set the schedule for climate zones, water heaters, and circulation pumps with [a custom service](https://signalkraft.com/mypyllant-component/1-automations/#setting-a-time-program) * Track sensor information of devices, such as temperature, humidity, operating mode, energy usage, or energy efficiency * See diagnostic information, such as the current heating curve, flow temperature, firmware versions, or water pressure * Custom services to set holiday mode or quick veto temperature overrides, and their duration diff --git a/custom_components/mypyllant/climate.py b/custom_components/mypyllant/climate.py index 74b15c8..9fe18ab 100644 --- a/custom_components/mypyllant/climate.py +++ b/custom_components/mypyllant/climate.py @@ -32,10 +32,10 @@ ) from myPyllant.models import ( System, - TimeProgramHeating, Zone, ZoneCurrentSpecialFunction, ZoneHeatingOperatingMode, + ZoneTimeProgram, ) from . import SystemCoordinator @@ -249,7 +249,7 @@ async def cancel_holiday(self): async def set_zone_time_program(self, **kwargs): _LOGGER.debug("Canceling holiday on System %s", self.system.id) program_type = kwargs.get("program_type") - time_program = TimeProgramHeating.from_api(**kwargs.get("time_program")) + time_program = ZoneTimeProgram.from_api(**kwargs.get("time_program")) await self.coordinator.api.set_zone_time_program( self.zone, program_type, time_program ) diff --git a/custom_components/mypyllant/const.py b/custom_components/mypyllant/const.py index 8f8cc05..2168794 100644 --- a/custom_components/mypyllant/const.py +++ b/custom_components/mypyllant/const.py @@ -15,3 +15,5 @@ SERVICE_SET_HOLIDAY = "set_holiday" SERVICE_CANCEL_HOLIDAY = "cancel_holiday" SERVICE_SET_ZONE_TIME_PROGRAM = "set_zone_time_program" +SERVICE_SET_DHW_TIME_PROGRAM = "set_dhw_time_program" +SERVICE_SET_DHW_CIRCULATION_TIME_PROGRAM = "set_dhw_circulation_time_program" diff --git a/custom_components/mypyllant/manifest.json b/custom_components/mypyllant/manifest.json index a2b925d..7dcb56c 100644 --- a/custom_components/mypyllant/manifest.json +++ b/custom_components/mypyllant/manifest.json @@ -7,6 +7,6 @@ "integration_type": "hub", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/signalkraft/issues", - "requirements": ["myPyllant==0.5.11"], - "version": "0.5.3" + "requirements": ["myPyllant==0.5.12"], + "version": "0.5.4" } diff --git a/custom_components/mypyllant/services.yaml b/custom_components/mypyllant/services.yaml index 3fc9cd4..2f4081c 100644 --- a/custom_components/mypyllant/services.yaml +++ b/custom_components/mypyllant/services.yaml @@ -150,4 +150,71 @@ set_zone_time_program: - start_time: 420 end_time: 1290 setpoint: 20 - type: heating + +set_dhw_time_program: + name: Set Water Heater Time Program + description: Updates the time program for a water heater + target: + entity: + integration: mypyllant + domain: water_heater + fields: + time_program: + name: Time Program + description: A dictionary of days with a list of start_time and end_time + example: > + monday: + - start_time: 330 + end_time: 1260 + tuesday: + - start_time: 330 + end_time: 1260 + wednesday: + - start_time: 330 + end_time: 1260 + thursday: + - start_time: 330 + end_time: 1260 + friday: + - start_time: 330 + end_time: 1260 + saturday: + - start_time: 450 + end_time: 1260 + sunday: + - start_time: 450 + end_time: 1260 + +set_dhw_circulation_time_program: + name: Set Water Heater Circulation Time Program + description: Updates the time program for the circulation pump of a water heater + target: + entity: + integration: mypyllant + domain: water_heater + fields: + time_program: + name: Time Program + description: A dictionary of days with a list of start_time and end_time + example: > + monday: + - start_time: 330 + end_time: 1260 + tuesday: + - start_time: 330 + end_time: 1260 + wednesday: + - start_time: 330 + end_time: 1260 + thursday: + - start_time: 330 + end_time: 1260 + friday: + - start_time: 330 + end_time: 1260 + saturday: + - start_time: 450 + end_time: 1260 + sunday: + - start_time: 450 + end_time: 1260 diff --git a/custom_components/mypyllant/water_heater.py b/custom_components/mypyllant/water_heater.py index dfad9a1..60818ea 100644 --- a/custom_components/mypyllant/water_heater.py +++ b/custom_components/mypyllant/water_heater.py @@ -1,6 +1,7 @@ import logging from typing import Any +import voluptuous as vol from homeassistant.components.water_heater import ( WaterHeaterEntity, WaterHeaterEntityFeature, @@ -8,18 +9,24 @@ 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 homeassistant.helpers.update_coordinator import CoordinatorEntity from myPyllant.models import ( DHWCurrentSpecialFunction, DHWOperationMode, + DHWTimeProgram, DomesticHotWater, System, ) from . import SystemCoordinator -from .const import DOMAIN +from .const import ( + DOMAIN, + SERVICE_SET_DHW_CIRCULATION_TIME_PROGRAM, + SERVICE_SET_DHW_TIME_PROGRAM, +) _LOGGER = logging.getLogger(__name__) @@ -42,6 +49,23 @@ async def async_setup_entry( dhws.append(DomesticHotWaterEntity(index, dhw_index, coordinator)) async_add_entities(dhws) + if len(dhws) > 0: + platform = entity_platform.async_get_current_platform() + _LOGGER.debug("Setting up water heater entity services for %s", platform) + platform.async_register_entity_service( + SERVICE_SET_DHW_TIME_PROGRAM, + { + vol.Required("time_program"): vol.All(dict), + }, + "set_dhw_time_program", + ) + platform.async_register_entity_service( + SERVICE_SET_DHW_CIRCULATION_TIME_PROGRAM, + { + vol.Required("time_program"): vol.All(dict), + }, + "set_dhw_circulation_time_program", + ) class DomesticHotWaterEntity(CoordinatorEntity, WaterHeaterEntity): @@ -154,3 +178,17 @@ async def async_set_operation_mode( DHWOperationMode(enum_value), ) await self.coordinator.async_request_refresh_delayed() + + async def set_dhw_time_program(self, **kwargs): + time_program = DHWTimeProgram.from_api(**kwargs.get("time_program")) + await self.coordinator.api.set_domestic_hot_water_time_program( + self.domestic_hot_water, time_program + ) + await self.coordinator.async_request_refresh_delayed() + + async def set_dhw_circulation_time_program(self, **kwargs): + time_program = DHWTimeProgram.from_api(**kwargs.get("time_program")) + await self.coordinator.api.set_domestic_hot_water_circulation_time_program( + self.domestic_hot_water, time_program + ) + await self.coordinator.async_request_refresh_delayed() diff --git a/dev-requirements.txt b/dev-requirements.txt index 238fe59..28808f8 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,16 +1,17 @@ -myPyllant==0.5.11 -aioresponses==0.7.4 -coverage>=6.3.1 -croniter>=1.3.8 -freezegun==1.2.2 -watchdog>=2.0.3 -mock-open==1.4.0 -mypy>=0.991 -pre-commit>=2.21.0 -pytest>=7.0.1 -pytest-cov>=2.9.0 +aioresponses~=0.7.4 +croniter~=1.3.8 +freezegun~=1.2.2 +watchdog~=2.0.3 +mock-open~=1.4.0 +mypy~=0.991 +pre-commit~=2.21.0 +pylint~=2.15.0 +pylint-strict-informational~=0.1 +polyfactory~=2.9.0 +pytest-asyncio~=0.21.0 + +# Need specific versions +pytest==7.3.1 +pytest-cov==4.1.0 pytest-homeassistant-custom-component==0.13.56 -pylint>=2.15.0 -pylint-strict-informational>=0.1 -polyfactory==2.9.0 -pytest-asyncio==0.21.0 +myPyllant==0.5.12 diff --git a/docs/docs/1-automations.md b/docs/docs/1-automations.md index 82a5d8e..0e21696 100644 --- a/docs/docs/1-automations.md +++ b/docs/docs/1-automations.md @@ -46,45 +46,111 @@ mode: single ## Setting a Time Program -Call the [mypyllant.time_program_heating service](https://my.home-assistant.io/redirect/developer_services/) with a `program_type` -and a `time_program`. +Call the `mypyllant.set_zone_time_program` (for climate) `mypyllant.set_dhw_time_program` (for water heaters) +with a `program_type` (only on climate) and a `time_program`. -```yaml -service: mypyllant.set_zone_time_program -data: - program_type: heating - time_program: - monday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - tuesday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - wednesday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - thursday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - friday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - saturday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - sunday: - - start_time: 420 - end_time: 1290 - setpoint: 20 - type: heating -target: - entity_id: climate.zone_0 -``` +=== "Climate" + + ```yaml + service: mypyllant.set_zone_time_program + data: + program_type: heating + time_program: + monday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + tuesday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + wednesday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + thursday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + friday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + saturday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + sunday: + - start_time: 420 + end_time: 1290 + setpoint: 20 + type: heating + target: + entity_id: climate.zone_0 + ``` + +=== "Water Heater" + + ```yaml + service: mypyllant.set_dhw_time_program + data: + time_program: + monday: + - start_time: 420 + end_time: 1290 + tuesday: + - start_time: 420 + end_time: 1290 + wednesday: + - start_time: 420 + end_time: 1290 + thursday: + - start_time: 420 + end_time: 1290 + friday: + - start_time: 420 + end_time: 1290 + saturday: + - start_time: 420 + end_time: 1290 + sunday: + - start_time: 420 + end_time: 1290 + type: heating + target: + entity_id: water_heater.domestic_hot_water_0 + ``` + +=== "Circulation Pump" + + ```yaml + service: mypyllant.set_dhw_circulation_time_program + data: + time_program: + monday: + - start_time: 420 + end_time: 1290 + tuesday: + - start_time: 420 + end_time: 1290 + wednesday: + - start_time: 420 + end_time: 1290 + thursday: + - start_time: 420 + end_time: 1290 + friday: + - start_time: 420 + end_time: 1290 + saturday: + - start_time: 420 + end_time: 1290 + sunday: + - start_time: 420 + end_time: 1290 + type: heating + target: + entity_id: water_heater.domestic_hot_water_0 + ``` [^1]: Contributed by CommanderROR in the [Home Assistant Community](https://community.home-assistant.io/t/myvaillant-integration/542610/70) \ No newline at end of file diff --git a/docs/docs/index.md b/docs/docs/index.md index 703a820..b425b13 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -55,8 +55,9 @@ Uses the [myPyllant library](https://github.com/signalkraft/mypyllant). * Supports climate & hot water controls, as well as sensor information * Control operating modes, target temperature, and presets such as holiday more or quick veto +* Set the schedule for climate zones, water heaters, and circulation pumps with [a custom service](https://signalkraft.com/mypyllant-component/1-automations/#setting-a-time-program) * Track sensor information of devices, such as temperature, humidity, operating mode, energy usage, or energy efficiency -* See diagnostic information, such as the current heating curve, flow temperature, or water pressure +* See diagnostic information, such as the current heating curve, flow temperature, firmware versions, or water pressure * Custom services to set holiday mode or quick veto temperature overrides, and their duration ## Options diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 51adab1..9fd806c 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -8,6 +8,7 @@ theme: scheme: slate features: - content.code.annotate + - content.tabs.link - navigation.tabs - navigation.tabs.sticky repo_url: https://github.com/signalkraft/mypyllant-component/ @@ -23,4 +24,6 @@ markdown_extensions: - pymdownx.inlinehilite - pymdownx.snippets - pymdownx.details - - pymdownx.superfences \ No newline at end of file + - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true \ No newline at end of file