Skip to content

Commit 59c7bc8

Browse files
committed
Implement try-except ConnectionFailedError constructs for all high-level set-funcs
1 parent bd1f2ac commit 59c7bc8

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

plugwise/__init__.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,10 @@ async def set_select(
324324
state: str | None = None,
325325
) -> None:
326326
"""Set the selected option for the applicable Select."""
327-
await self._smile_api.set_select(key, loc_id, option, state)
327+
try:
328+
await self._smile_api.set_select(key, loc_id, option, state)
329+
except ConnectionFailedError as exc:
330+
raise PlugwiseError(f"Failed to set select: {str(exc)}") from exc
328331

329332
async def set_schedule_state(
330333
self,
@@ -333,15 +336,25 @@ async def set_schedule_state(
333336
name: str | None = None,
334337
) -> None:
335338
"""Activate/deactivate the Schedule, with the given name, on the relevant Thermostat."""
336-
await self._smile_api.set_schedule_state(loc_id, state, name)
339+
try:
340+
await self._smile_api.set_schedule_state(loc_id, state, name)
341+
except ConnectionFailedError as exc:
342+
raise PlugwiseError(f"Failed to set schedule state: {str(exc)}") from exc
343+
337344

338345
async def set_preset(self, loc_id: str, preset: str) -> None:
339346
"""Set the given Preset on the relevant Thermostat."""
340-
await self._smile_api.set_preset(loc_id, preset)
347+
try:
348+
await self._smile_api.set_preset(loc_id, preset)
349+
except ConnectionFailedError as exc:
350+
raise PlugwiseError(f"Failed to set preset: {str(exc)}") from exc
341351

342352
async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
343353
"""Set the given Temperature on the relevant Thermostat."""
344-
await self._smile_api.set_temperature(loc_id, items)
354+
try:
355+
await self._smile_api.set_temperature(loc_id, items)
356+
except ConnectionFailedError as exc:
357+
raise PlugwiseError(f"Failed to set temperature: {str(exc)}") from exc
345358

346359
async def set_number(
347360
self,
@@ -350,29 +363,47 @@ async def set_number(
350363
temperature: float,
351364
) -> None:
352365
"""Set the maximum boiler- or DHW-setpoint on the Central Heating boiler or the temperature-offset on a Thermostat."""
353-
await self._smile_api.set_number(dev_id, key, temperature)
366+
try:
367+
await self._smile_api.set_number(dev_id, key, temperature)
368+
except ConnectionFailedError as exc:
369+
raise PlugwiseError(f"Failed to set number: {str(exc)}") from exc
354370

355371
async def set_temperature_offset(self, dev_id: str, offset: float) -> None:
356372
"""Set the Temperature offset for thermostats that support this feature."""
357-
await self._smile_api.set_offset(dev_id, offset) # pragma: no cover
373+
try:
374+
await self._smile_api.set_offset(dev_id, offset) # pragma: no cover
375+
except ConnectionFailedError as exc:
376+
raise PlugwiseError(f"Failed to set temperature offset: {str(exc)}") from exc
358377

359378
async def set_switch_state(
360379
self, appl_id: str, members: list[str] | None, model: str, state: str
361380
) -> None:
362381
"""Set the given State of the relevant Switch."""
363-
await self._smile_api.set_switch_state(appl_id, members, model, state)
382+
try:
383+
await self._smile_api.set_switch_state(appl_id, members, model, state)
384+
except ConnectionFailedError as exc:
385+
raise PlugwiseError(f"Failed to set switch state: {str(exc)}") from exc
364386

365387
async def set_gateway_mode(self, mode: str) -> None:
366388
"""Set the gateway mode."""
367-
await self._smile_api.set_gateway_mode(mode) # pragma: no cover
389+
try:
390+
await self._smile_api.set_gateway_mode(mode) # pragma: no cover
391+
except ConnectionFailedError as exc:
392+
raise PlugwiseError(f"Failed to set gateway mode: {str(exc)}") from exc
368393

369394
async def set_regulation_mode(self, mode: str) -> None:
370395
"""Set the heating regulation mode."""
371-
await self._smile_api.set_regulation_mode(mode) # pragma: no cover
396+
try:
397+
await self._smile_api.set_regulation_mode(mode) # pragma: no cover
398+
except ConnectionFailedError as exc:
399+
raise PlugwiseError(f"Failed to set regulation mode: {str(exc)}") from exc
372400

373401
async def set_dhw_mode(self, mode: str) -> None:
374402
"""Set the domestic hot water heating regulation mode."""
375-
await self._smile_api.set_dhw_mode(mode) # pragma: no cover
403+
try:
404+
await self._smile_api.set_dhw_mode(mode) # pragma: no cover
405+
except ConnectionFailedError as exc:
406+
raise PlugwiseError(f"Failed to set dhw mode: {str(exc)}") from exc
376407

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

0 commit comments

Comments
 (0)