Skip to content

Commit 7d3fc05

Browse files
committed
Start adding set_select() function
1 parent 7986ccb commit 7d3fc05

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

plugwise/__init__.py

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

309+
async def set_select(self, key: str, loc_id: str, option: str, name: str) -> None:
310+
"""Set the selected option for the applicable Select."""
311+
await self._smile_api.set_select(loc_id, option)
312+
309313
async def set_schedule_state(
310314
self,
311315
loc_id: str,

plugwise/smile.py

Lines changed: 45 additions & 33 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,51 @@ 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:
212+
"""Set a dhw/gateway/regulation mode or the thermostat schedule option."""
213+
match key:
214+
case "select_dhw_mode":
215+
await set_dhw_mode(option)
216+
case: "select_gateway_mode":
217+
await set_gateway_mode(option)
218+
case "select_regulation_mode":
219+
await set_regulation_mode(option)
220+
case "select_schedule":
221+
await set_schedule_state(loc_id, option, name)
222+
223+
async def set_dhw_mode(self, mode: str) -> None:
224+
"""Set the domestic hot water heating regulation mode."""
225+
if mode not in self._dhw_allowed_modes:
226+
raise PlugwiseError("Plugwise: invalid dhw mode.")
227+
228+
uri = f"{APPLIANCES};type=heater_central/domestic_hot_water_mode_control"
229+
data = f"<domestic_hot_water_mode_control_functionality><mode>{mode}</mode></domestic_hot_water_mode_control_functionality>"
230+
231+
await self._request(uri, method="put", data=data)
232+
233+
async def set_gateway_mode(self, mode: str) -> None:
234+
"""Set the gateway mode."""
235+
if mode not in self._gw_allowed_modes:
236+
raise PlugwiseError("Plugwise: invalid gateway mode.")
237+
238+
end_time = "2037-04-21T08:00:53.000Z"
239+
valid = ""
240+
if mode == "away":
241+
time_1 = self._domain_objects.find("./gateway/time").text
242+
away_time = dt.datetime.fromisoformat(time_1).astimezone(dt.UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
243+
valid = (
244+
f"<valid_from>{away_time}</valid_from><valid_to>{end_time}</valid_to>"
245+
)
246+
if mode == "vacation":
247+
time_2 = str(dt.date.today() - dt.timedelta(1))
248+
vacation_time = time_2 + "T23:00:00.000Z"
249+
valid = f"<valid_from>{vacation_time}</valid_from><valid_to>{end_time}</valid_to>"
250+
251+
uri = f"{APPLIANCES};id={self.gateway_id}/gateway_mode_control"
252+
data = f"<gateway_mode_control_functionality><mode>{mode}</mode>{valid}</gateway_mode_control_functionality>"
253+
254+
await self._request(uri, method="put", data=data)
255+
244256
async def set_regulation_mode(self, mode: str) -> None:
245257
"""Set the heating regulation mode."""
246258
if mode not in self._reg_allowed_modes:

0 commit comments

Comments
 (0)