Skip to content

Commit b635c47

Browse files
authored
Merge pull request #560 from plugwise/set_select
Create a set_select() function, combining the set_dhw_mode(), set_gateway_mode(), set_regulation_mode() and set_schedule_state() functions.
2 parents 7986ccb + e1dcc50 commit b635c47

File tree

6 files changed

+79
-43
lines changed

6 files changed

+79
-43
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.37.8
4+
5+
- Create a set_select() function, combining the set_dhw_mode(), set_gateway_mode(), set_regulation_mode() and set_schedule_state() functions.
6+
37
## v0.37.7
48

59
- Don't output schedule-related data when no valid schedule(s) found.
@@ -17,6 +21,8 @@
1721

1822
## v0.37.4 - not released
1923

24+
- Create a set_number() function, combining the set_number_setpoint() and set_temperature_offset() functions.
25+
2026
## v0.37.3
2127

2228
- Fix for [plugwise-beta #620](https://github.com/plugwise/plugwise-beta/issues/620).

plugwise/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ async def async_update(self) -> PlugwiseData:
306306
### API Set and HA Service-related Functions ###
307307
########################################################################################################
308308

309+
async def set_select(
310+
self,
311+
key: str,
312+
loc_id: str,
313+
option: str,
314+
name: str | None = None,
315+
) -> None:
316+
"""Set the selected option for the applicable Select."""
317+
await self._smile_api.set_select(key, loc_id, option, name)
318+
309319
async def set_schedule_state(
310320
self,
311321
loc_id: str,
@@ -344,15 +354,15 @@ async def set_switch_state(
344354

345355
async def set_gateway_mode(self, mode: str) -> None:
346356
"""Set the gateway mode."""
347-
await self._smile_api.set_gateway_mode(mode)
357+
await self._smile_api.set_gateway_mode(mode) # pragma: no cover
348358

349359
async def set_regulation_mode(self, mode: str) -> None:
350360
"""Set the heating regulation mode."""
351-
await self._smile_api.set_regulation_mode(mode)
361+
await self._smile_api.set_regulation_mode(mode) # pragma: no cover
352362

353363
async def set_dhw_mode(self, mode: str) -> None:
354364
"""Set the domestic hot water heating regulation mode."""
355-
await self._smile_api.set_dhw_mode(mode)
365+
await self._smile_api.set_dhw_mode(mode) # pragma: no cover
356366

357367
async def delete_notification(self) -> None:
358368
"""Delete the active Plugwise Notification."""

plugwise/legacy/smile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ async def set_preset(self, _: str, preset: str) -> None:
182182
async def set_regulation_mode(self, mode: str) -> None:
183183
"""Set-function placeholder for legacy devices."""
184184

185+
async def set_select(self, key: str, loc_id: str, option: str, name: str | None) -> None:
186+
"""Set the thermostat schedule option."""
187+
# schedule state corresponds to select option
188+
# schedule name corresponds to select name
189+
await self.set_schedule_state("dummy", option, name)
190+
185191
async def set_schedule_state(self, _: str, state: str, name: str | None) -> None:
186192
"""Activate/deactivate the Schedule.
187193

plugwise/smile.py

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -149,39 +149,6 @@ async def delete_notification(self) -> None:
149149
"""Delete the active Plugwise Notification."""
150150
await self._request(NOTIFICATIONS, method="delete")
151151

152-
async def set_dhw_mode(self, mode: str) -> None:
153-
"""Set the domestic hot water heating regulation mode."""
154-
if mode not in self._dhw_allowed_modes:
155-
raise PlugwiseError("Plugwise: invalid dhw mode.")
156-
157-
uri = f"{APPLIANCES};type=heater_central/domestic_hot_water_mode_control"
158-
data = f"<domestic_hot_water_mode_control_functionality><mode>{mode}</mode></domestic_hot_water_mode_control_functionality>"
159-
160-
await self._request(uri, method="put", data=data)
161-
162-
async def set_gateway_mode(self, mode: str) -> None:
163-
"""Set the gateway mode."""
164-
if mode not in self._gw_allowed_modes:
165-
raise PlugwiseError("Plugwise: invalid gateway mode.")
166-
167-
end_time = "2037-04-21T08:00:53.000Z"
168-
valid = ""
169-
if mode == "away":
170-
time_1 = self._domain_objects.find("./gateway/time").text
171-
away_time = dt.datetime.fromisoformat(time_1).astimezone(dt.UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
172-
valid = (
173-
f"<valid_from>{away_time}</valid_from><valid_to>{end_time}</valid_to>"
174-
)
175-
if mode == "vacation":
176-
time_2 = str(dt.date.today() - dt.timedelta(1))
177-
vacation_time = time_2 + "T23:00:00.000Z"
178-
valid = f"<valid_from>{vacation_time}</valid_from><valid_to>{end_time}</valid_to>"
179-
180-
uri = f"{APPLIANCES};id={self.gateway_id}/gateway_mode_control"
181-
data = f"<gateway_mode_control_functionality><mode>{mode}</mode>{valid}</gateway_mode_control_functionality>"
182-
183-
await self._request(uri, method="put", data=data)
184-
185152
async def set_number(
186153
self,
187154
dev_id: str,
@@ -241,6 +208,53 @@ async def set_preset(self, loc_id: str, preset: str) -> None:
241208

242209
await self._request(uri, method="put", data=data)
243210

211+
async def set_select(self, key: str, loc_id: str, option: str, name: str | None) -> None:
212+
"""Set a dhw/gateway/regulation mode or the thermostat schedule option."""
213+
match key:
214+
case "select_dhw_mode":
215+
await self.set_dhw_mode(option)
216+
case "select_gateway_mode":
217+
await self.set_gateway_mode(option)
218+
case "select_regulation_mode":
219+
await self.set_regulation_mode(option)
220+
case "select_schedule":
221+
# schedule state corresponds to select option
222+
# schedule name corresponds to select name
223+
await self.set_schedule_state(loc_id, option, name)
224+
225+
async def set_dhw_mode(self, mode: str) -> None:
226+
"""Set the domestic hot water heating regulation mode."""
227+
if mode not in self._dhw_allowed_modes:
228+
raise PlugwiseError("Plugwise: invalid dhw mode.")
229+
230+
uri = f"{APPLIANCES};type=heater_central/domestic_hot_water_mode_control"
231+
data = f"<domestic_hot_water_mode_control_functionality><mode>{mode}</mode></domestic_hot_water_mode_control_functionality>"
232+
233+
await self._request(uri, method="put", data=data)
234+
235+
async def set_gateway_mode(self, mode: str) -> None:
236+
"""Set the gateway mode."""
237+
if mode not in self._gw_allowed_modes:
238+
raise PlugwiseError("Plugwise: invalid gateway mode.")
239+
240+
end_time = "2037-04-21T08:00:53.000Z"
241+
valid = ""
242+
if mode == "away":
243+
time_1 = self._domain_objects.find("./gateway/time").text
244+
away_time = dt.datetime.fromisoformat(time_1).astimezone(dt.UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
245+
valid = (
246+
f"<valid_from>{away_time}</valid_from><valid_to>{end_time}</valid_to>"
247+
)
248+
if mode == "vacation":
249+
time_2 = str(dt.date.today() - dt.timedelta(1))
250+
vacation_time = time_2 + "T23:00:00.000Z"
251+
valid = f"<valid_from>{vacation_time}</valid_from><valid_to>{end_time}</valid_to>"
252+
253+
uri = f"{APPLIANCES};id={self.gateway_id}/gateway_mode_control"
254+
data = f"<gateway_mode_control_functionality><mode>{mode}</mode>{valid}</gateway_mode_control_functionality>"
255+
256+
await self._request(uri, method="put", data=data)
257+
244258
async def set_regulation_mode(self, mode: str) -> None:
245259
"""Set the heating regulation mode."""
246260
if mode not in self._reg_allowed_modes:
@@ -258,7 +272,7 @@ async def set_schedule_state(
258272
self,
259273
loc_id: str,
260274
new_state: str,
261-
name: str | None = None,
275+
name: str | None,
262276
) -> None:
263277
"""Activate/deactivate the Schedule, with the given name, on the relevant Thermostat.
264278

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "0.37.7"
7+
version = "0.37.8"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

tests/test_init.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ async def tinker_thermostat_schedule(
733733
new_schedule = new_schedule[1:]
734734
_LOGGER.info("- Adjusting schedule to %s", f"{new_schedule}{warning}")
735735
try:
736-
await smile.set_schedule_state(loc_id, state, new_schedule)
736+
await smile.set_select("select_schedule", loc_id, state, new_schedule)
737737
tinker_schedule_passed = True
738738
_LOGGER.info(" + working as intended")
739739
except pw_exceptions.PlugwiseError:
@@ -763,7 +763,7 @@ async def tinker_legacy_thermostat_schedule(self, smile, unhappy=False):
763763
for state in states:
764764
_LOGGER.info("- Adjusting schedule to state %s", state)
765765
try:
766-
await smile.set_schedule_state(None, state)
766+
await smile.set_select("select_schedule", "dummy", state)
767767
tinker_schedule_passed = True
768768
_LOGGER.info(" + working as intended")
769769
except pw_exceptions.PlugwiseError:
@@ -847,7 +847,7 @@ async def tinker_dhw_mode(smile):
847847
mode = mode[1:]
848848
_LOGGER.info("%s", f"- Adjusting dhw mode to {mode}{warning}")
849849
try:
850-
await smile.set_dhw_mode(mode)
850+
await smile.set_select("select_dhw_mode", "dummy", mode)
851851
_LOGGER.info(" + tinker_dhw_mode worked as intended")
852852
except pw_exceptions.PlugwiseError:
853853
_LOGGER.info(" + tinker_dhw_mode found invalid mode, as expected")
@@ -862,7 +862,7 @@ async def tinker_regulation_mode(smile):
862862
mode = mode[1:]
863863
_LOGGER.info("%s", f"- Adjusting regulation mode to {mode}{warning}")
864864
try:
865-
await smile.set_regulation_mode(mode)
865+
await smile.set_select("select_regulation_mode", "dummy", mode)
866866
_LOGGER.info(" + tinker_regulation_mode worked as intended")
867867
except pw_exceptions.PlugwiseError:
868868
_LOGGER.info(
@@ -904,7 +904,7 @@ async def tinker_gateway_mode(smile):
904904
mode = mode[1:]
905905
_LOGGER.info("%s", f"- Adjusting gateway mode to {mode}{warning}")
906906
try:
907-
await smile.set_gateway_mode(mode)
907+
await smile.set_select("select_gateway_mode", "dummy", mode)
908908
_LOGGER.info(" + worked as intended")
909909
except pw_exceptions.PlugwiseError:
910910
_LOGGER.info(" + found invalid mode, as expected")

0 commit comments

Comments
 (0)