diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f0f82f3e..d2e640ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.8.3 + +- Remove storing the last active schedule(s) via PR [#806](https://github.com/plugwise/python-plugwise/pull/806), to be handled by the HA Integration + ## v1.8.2 - Add support for Emma Pro wired, rename wireless Emma to Emma Pro via PR [#804](https://github.com/plugwise/python-plugwise/pull/804) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 47abbd837..2b89b065f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -67,7 +67,6 @@ def __init__( self._cooling_present = False self._elga = False self._is_thermostat = False - self._last_active: dict[str, str | None] = {} self._loc_data: dict[str, ThermoLoc] = {} self._on_off_device = False self._opentherm_device = False @@ -156,7 +155,6 @@ async def connect(self) -> Version: self._cooling_present, self._elga, self._is_thermostat, - self._last_active, self._loc_data, self._on_off_device, self._opentherm_device, diff --git a/plugwise/helper.py b/plugwise/helper.py index 4ed5347d6..0d7355ee0 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -5,7 +5,6 @@ from __future__ import annotations -import datetime as dt from typing import cast from plugwise.common import SmileCommon @@ -50,9 +49,6 @@ skip_obsolete_measurements, ) -# Time related -from dateutil import tz -from dateutil.parser import parse from defusedxml import ElementTree as etree from munch import Munch from packaging import version @@ -78,7 +74,6 @@ def __init__(self) -> None: self._endpoint: str self._elga: bool self._is_thermostat: bool - self._last_active: dict[str, str | None] self._loc_data: dict[str, ThermoLoc] self._schedule_old_states: dict[str, dict[str, str]] self._gateway_id: str = NONE @@ -871,7 +866,7 @@ def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str, dict[str, str]] return schedule_ids def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, dict[str, str]]: - """Helper-function for _presets(), _schedules() and _last_active_schedule(). + """Helper-function for _presets() and _schedules(). Obtain the rule_id from the given template_tag and provide the location_id, when present. """ @@ -906,11 +901,6 @@ def _schedules(self, location: str) -> tuple[list[str], str]: available: list[str] = [NONE] rule_ids: dict[str, dict[str, str]] = {} selected = NONE - # Adam schedules, one schedule can be linked to various locations - # self._last_active contains the locations and the active schedule name per location, or None - if location not in self._last_active: - self._last_active[location] = None - tag = "zone_preset_based_on_time_and_presence_with_override" if not (rule_ids := self._rule_ids_by_tag(tag, location)): return available, selected @@ -927,7 +917,6 @@ def _schedules(self, location: str) -> tuple[list[str], str]: available.append(name) if location == data["location"] and active: selected = name - self._last_active[location] = selected schedules.append(name) if schedules: @@ -935,26 +924,9 @@ def _schedules(self, location: str) -> tuple[list[str], str]: available.append(OFF) if selected == NONE: selected = OFF - if self._last_active.get(location) is None: - self._last_active[location] = self._last_used_schedule(schedules) - - return available, selected - def _last_used_schedule(self, schedules: list[str]) -> str: - """Helper-function for _schedules(). - Determine the last-used schedule based on the modified date. - """ - epoch = dt.datetime(1970, 1, 1, tzinfo=tz.tzutc()) - schedules_dates: dict[str, float] = {} - - for name in schedules: - result = self._domain_objects.find(f'./rule[name="{name}"]') - schedule_date = result.find("modified_date").text - schedule_time = parse(schedule_date) - schedules_dates[name] = (schedule_time - epoch).total_seconds() - - return sorted(schedules_dates.items(), key=lambda kv: kv[1])[-1][0] + return available, selected def _thermostat_uri(self, loc_id: str) -> str: """Helper-function for smile.py: set_temperature(). diff --git a/plugwise/smile.py b/plugwise/smile.py index 970181ca1..bfeb61817 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -68,7 +68,6 @@ def __init__( _cooling_present: bool, _elga: bool, _is_thermostat: bool, - _last_active: dict[str, str | None], _loc_data: dict[str, ThermoLoc], _on_off_device: bool, _opentherm_device: bool, @@ -81,7 +80,6 @@ def __init__( self._cooling_present = _cooling_present self._elga = _elga self._is_thermostat = _is_thermostat - self._last_active = _last_active self._loc_data = _loc_data self._on_off_device = _on_off_device self._opentherm_device = _opentherm_device @@ -325,14 +323,12 @@ async def set_schedule_state( if name == OFF: new_state = STATE_OFF - # Handle no schedule-name / Off-schedule provided + # Handle no schedule-name / schedule-off requested: find the active schedule if name is None or name == OFF: - if schedule_name := self._last_active[loc_id]: - name = schedule_name - else: + _, name = self._schedules(loc_id) + if name == OFF: # no active schedule found, nothing to do return - assert isinstance(name, str) schedule_rule = self._rule_ids_by_name(name, loc_id) # Raise an error when the schedule name does not exist if not schedule_rule or schedule_rule is None: @@ -351,7 +347,7 @@ async def set_schedule_state( template_id = self._domain_objects.find(locator).attrib["id"] template = f'