Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changelog

## Ongoing
## v1.11.1

- Code optimizations via PR [#837](https://github.com/plugwise/python-plugwise/pull/837), [#838](https://github.com/plugwise/python-plugwise/pull/838), [#839](https://github.com/plugwise/python-plugwise/pull/839), [#840](https://github.com/plugwise/python-plugwise/pull/840)
- Code optimizations via PR [#837](https://github.com/plugwise/python-plugwise/pull/837), [#838](https://github.com/plugwise/python-plugwise/pull/838), [#839](https://github.com/plugwise/python-plugwise/pull/839), [#840](https://github.com/plugwise/python-plugwise/pull/840), and [#841](https://github.com/plugwise/python-plugwise/pull/841)

## v1.11.0

Expand Down
5 changes: 3 additions & 2 deletions plugwise/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch

def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
"""Helper-function for _appliance_info_finder()."""
self._gateway_id = appliance.get("id")
appl.firmware = str(self.smile.version)
self._gateway_id = appl.entity_id
locator = "./gateway/firmware_version"
appl.firmware = self._domain_objects.find(locator).text
Comment on lines +275 to +277
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

git ls-files plugwise/ | head -20

Repository: plugwise/python-plugwise

Length of output: 338


🏁 Script executed:

cat -n plugwise/helper.py | sed -n '270,310p'

Repository: plugwise/python-plugwise

Length of output: 2124


🏁 Script executed:

cat -n plugwise/helper.py | sed -n '60,70p'

Repository: plugwise/python-plugwise

Length of output: 566


🏁 Script executed:

cat -n plugwise/helper.py | sed -n '285,295p'

Repository: plugwise/python-plugwise

Length of output: 688


🏁 Script executed:

cat -n plugwise/helper.py | sed -n '635,645p'

Repository: plugwise/python-plugwise

Length of output: 834


🏁 Script executed:

rg -n 'gateway.*firmware' --type=py -B2 -A2

Repository: plugwise/python-plugwise

Length of output: 1288


🏁 Script executed:

fd -e xml -e json | head -20

Repository: plugwise/python-plugwise

Length of output: 860


🏁 Script executed:

find . -type f \( -name "*.xml" -o -name "*.json" \) | grep -i test | head -10

Repository: plugwise/python-plugwise

Length of output: 525


🏁 Script executed:

# Check one of the test data files to understand the XML structure
head -100 ./tests/data/adam/adam_plus_anna.json

Repository: plugwise/python-plugwise

Length of output: 2816


🏁 Script executed:

# Search for firmware_version in test data to see if it's consistently present
rg -n 'firmware_version' ./tests/data/ | head -20

Repository: plugwise/python-plugwise

Length of output: 50


🏁 Script executed:

cat -n plugwise/__init__.py | sed -n '188,210p'

Repository: plugwise/python-plugwise

Length of output: 1196


🏁 Script executed:

cat -n plugwise/__init__.py | sed -n '298,310p'

Repository: plugwise/python-plugwise

Length of output: 863


🏁 Script executed:

rg -n '_appl_gateway_info' --type=py -B3 -A5

Repository: plugwise/python-plugwise

Length of output: 1335


Add None-check before accessing .text to prevent AttributeError.

The code directly calls .text on the result of .find() without checking if the element exists. If the ./gateway/firmware_version element is not present in the XML, this will raise an AttributeError. Throughout this codebase, the pattern is to check for None before accessing .text (see lines 64-65, 638-641).

 def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
     """Helper-function for _appliance_info_finder()."""
     self._gateway_id = appl.entity_id
     locator = "./gateway/firmware_version"
-    appl.firmware = self._domain_objects.find(locator).text
+    if (firmware_elem := self._domain_objects.find(locator)) is not None:
+        appl.firmware = firmware_elem.text
+    else:
+        appl.firmware = None  # or provide appropriate fallback
     appl.hardware = self.smile.hw_version
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self._gateway_id = appl.entity_id
locator = "./gateway/firmware_version"
appl.firmware = self._domain_objects.find(locator).text
self._gateway_id = appl.entity_id
locator = "./gateway/firmware_version"
if (firmware_elem := self._domain_objects.find(locator)) is not None:
appl.firmware = firmware_elem.text
else:
appl.firmware = None # or provide appropriate fallback
🤖 Prompt for AI Agents
In plugwise/helper.py around lines 275 to 277, the code calls .text on the
result of self._domain_objects.find("./gateway/firmware_version") without
checking for None; add a None-check for the returned element and only read .text
when the element exists, otherwise set appl.firmware to None (or an appropriate
default) to avoid AttributeError.

appl.hardware = self.smile.hw_version
appl.mac = self.smile.mac_address
appl.model = self.smile.model
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "plugwise"
version = "1.11.0"
version = "1.11.1"
license = "MIT"
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
readme = "README.md"
Expand Down
Loading