Skip to content

Commit 1e6dc96

Browse files
authored
Merge pull request #177 from plugwise/revert_debugs
Revert removal of error-logging
2 parents 253d278 + d7e4551 commit 1e6dc96

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

CHANGELOG.md

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

3+
# v0.17.6: Smile: revert removing LOGGER.error messages
4+
35
# v0.17.5: Smile: rework to raise instead of return
46
- raise in error-cases, move LOGGER.debug messages into raise
57
- clean up code

plugwise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Plugwise module."""
22

3-
__version__ = "0.17.5"
3+
__version__ = "0.17.6"
44

55
from plugwise.smile import Smile
66
from plugwise.stick import Stick

plugwise/helper.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,22 @@ async def _request_validate(self, resp: ClientResponse, method: str) -> etree:
227227
return
228228

229229
if resp.status == 401:
230-
raise InvalidAuthentication(
231-
"Invalid login, please retry with the correct credentials."
232-
)
230+
msg = "Invalid Plugwise login, please retry with the correct credentials."
231+
LOGGER.error("%s", msg)
232+
raise InvalidAuthentication(f"{msg}")
233233

234234
if not (result := await resp.text()) or "<error>" in result:
235-
raise ResponseError(f"Smile response empty or error in {result}.")
235+
LOGGER.error("Smile response empty or error in %s", result)
236+
raise ResponseError("Plugwise response error, check log for more info.")
236237

237238
try:
238239
# Encode to ensure utf8 parsing
239240
xml = etree.XML(escape_illegal_xml_characters(result).encode())
240241
except etree.ParseError:
241-
raise InvalidXMLError(f"Smile returns invalid XML for {self._endpoint}.")
242+
LOGGER.error("Smile returns invalid XML for %s", self._endpoint)
243+
raise InvalidXMLError(
244+
"Plugwise invalid XML error, check log for more info."
245+
)
242246

243247
return xml
244248

@@ -271,8 +275,9 @@ async def _request(
271275
)
272276
except ServerTimeoutError:
273277
if retry < 1:
278+
LOGGER.error("Timed out sending %s command to Plugwise", command)
274279
raise DeviceTimeoutError(
275-
f"Timed out sending {command} command to Plugwise"
280+
"Plugwise timeout error, check log for more info."
276281
)
277282
return await self._request(command, retry - 1)
278283

plugwise/smile.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,20 @@ async def connect(self) -> bool:
275275
dsmrmain = result.find("./module/protocols/dsmrmain")
276276
if "Plugwise" not in names:
277277
if dsmrmain is None: # pragma: no cover
278-
raise ConnectionFailedError(
279-
f"Connected but expected text not returned, \
280-
we got {result}. Please create an issue on \
281-
http://github.com/plugwise/python-plugwise"
278+
LOGGER.error(
279+
"Connected but expected text not returned, we got %s. Please create \
280+
an issue on http://github.com/plugwise/python-plugwise",
281+
result,
282282
)
283+
raise ConnectionFailedError("Plugwise error, check log for more info.")
283284

284285
# Check if Anna is connected to an Adam
285286
if "159.2" in models:
287+
LOGGER.error(
288+
"Your Anna is connected to an Adam, make sure to only add the Adam as integration."
289+
)
286290
raise InvalidSetupError(
287-
"Your Anna is connected to an Adam, make \
288-
sure to only add the Adam as integration."
291+
"Plugwise invalid setup error, check log for more info."
289292
)
290293

291294
# Determine smile specifics
@@ -337,10 +340,11 @@ async def _smile_detect_legacy(self, result: etree, dsmrmain: etree) -> str:
337340

338341
else: # pragma: no cover
339342
# No cornercase, just end of the line
340-
raise ConnectionFailedError(
343+
LOGGER.error(
341344
"Connected but no gateway device information found, please create \
342345
an issue on http://github.com/plugwise/python-plugwise"
343346
)
347+
raise ConnectionFailedError("Plugwise error, check log for more info.")
344348

345349
return model
346350

@@ -360,20 +364,22 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
360364

361365
if model is None or self.smile_fw_version is None: # pragma: no cover
362366
# Corner case check
363-
raise UnsupportedDeviceError(
367+
LOGGER.error(
364368
"Unable to find model or version information, please create \
365369
an issue on http://github.com/plugwise/python-plugwise"
366370
)
371+
raise UnsupportedDeviceError("Plugwise error, check log for more info.")
367372

368373
ver = semver.VersionInfo.parse(self.smile_fw_version)
369374
target_smile = f"{model}_v{ver.major}"
370375
LOGGER.debug("Plugwise identified as %s", target_smile)
371376
if target_smile not in SMILES:
372-
raise UnsupportedDeviceError(
373-
"Your version Smile identified as {target_smile} seems\
374-
unsupported by our plugin, please create an issue\
375-
on http://github.com/plugwise/python-plugwise"
377+
LOGGER.error(
378+
'Your version Smile identified as "%s" seems unsupported by our plugin, please \
379+
create an issue on http://github.com/plugwise/python-plugwise',
380+
target_smile,
376381
)
382+
raise UnsupportedDeviceError("Plugwise error, check log for more info.")
377383

378384
self.smile_name = SMILES[target_smile]["friendly_name"]
379385
self.smile_type = SMILES[target_smile]["type"]
@@ -467,7 +473,7 @@ async def _set_schedule_state_legacy(self, name: str, status: str) -> None:
467473
schedule_rule_id = rule.attrib["id"]
468474

469475
if schedule_rule_id is None:
470-
raise PlugwiseError("No schedule available.")
476+
raise PlugwiseError("Plugwise: no schedule available.")
471477

472478
state = "false"
473479
if status == "on":
@@ -495,7 +501,7 @@ async def set_schedule_state(self, loc_id: str, name: str, state: str) -> None:
495501

496502
schedule_rule = self._rule_ids_by_name(name, loc_id)
497503
if not schedule_rule or schedule_rule is None:
498-
raise PlugwiseError("No schedule with this name available.")
504+
raise PlugwiseError("Plugwise: no schedule with this name available.")
499505

500506
schedule_rule_id: str = next(iter(schedule_rule))
501507

@@ -534,7 +540,7 @@ async def _set_preset_legacy(self, preset: str) -> None:
534540
"""Set the given Preset on the relevant Thermostat - from DOMAIN_OBJECTS."""
535541
locator = f'rule/directives/when/then[@icon="{preset}"].../.../...'
536542
if (rule := self._domain_objects.find(locator)) is None:
537-
raise PlugwiseError("Invalid preset.")
543+
raise PlugwiseError("Plugwise: invalid preset.")
538544

539545
uri = RULES
540546
data = f'<rules><rule id="{rule.attrib["id"]}"><active>true</active></rule></rules>'
@@ -552,7 +558,7 @@ async def set_preset(self, loc_id: str, preset: str) -> None:
552558
location_type = current_location.find("type").text
553559

554560
if preset not in self._presets(loc_id):
555-
raise PlugwiseError("Invalid preset.")
561+
raise PlugwiseError("Plugwise: invalid preset.")
556562

557563
uri = f"{LOCATIONS};id={loc_id}"
558564
data = (
@@ -639,14 +645,14 @@ async def set_switch_state(
639645
lock_state: str = self._appliances.find(locator).text
640646
# Don't bother switching a relay when the corresponding lock-state is true
641647
if lock_state == "true":
642-
raise PlugwiseError("Cannot switch a locked Relay.")
648+
raise PlugwiseError("Plugwise: the locked Relay was not switched.")
643649

644650
await self._request(uri, method="put", data=data)
645651

646652
async def set_regulation_mode(self, mode: str) -> None:
647653
"""Set the heating regulation mode."""
648654
if mode not in self._allowed_modes:
649-
raise PlugwiseError("Invalid regulation mode.")
655+
raise PlugwiseError("Plugwise: invalid regulation mode.")
650656

651657
uri = f"{APPLIANCES};type=gateway/regulation_mode_control"
652658
duration = ""

0 commit comments

Comments
 (0)