forked from abacao/hass_wibeee
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use values.xml api when polling sensor values (#83)
* remove status.xml support * use values.xml instead of values2.xml * ensure WiFi secrets are scrubbed from logs * ensure correct requirements in manifest.json * update HACS action
- Loading branch information
Showing
8 changed files
with
201 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import re | ||
from io import BytesIO | ||
|
||
from lxml import etree | ||
|
||
|
||
def short_mac(mac_addr): | ||
"""Returns the last 6 chars of the MAC address for showing in UI.""" | ||
return mac_addr.replace(':', '')[-6:].upper() | ||
|
||
|
||
def scrub_xml_text_naively(keys: list[str], xml_text: str) -> str: | ||
"""Naively use a RegEx (facepalm) to scrub values from XML text.""" | ||
scrubbed_text = re.sub(f'<({"|".join(keys)})>.*?</\\1>', f'<\\1>*MASKED*</\\1>', xml_text) | ||
return scrubbed_text | ||
|
||
def scrub_values_xml(keys: list[str], xml_text: bytes) -> str: | ||
"""Scrubs sensitive data from the values.xml response.""" | ||
tree = etree.parse(BytesIO(xml_text)) | ||
|
||
def scrub_dict_top_level(keys: list[str], values: dict) -> dict: | ||
"""Scrubs values from """ | ||
scrubbed_values = dict(values) | ||
for scrub_key in keys: | ||
if scrub_key in values: | ||
scrubbed_values.update({scrub_key: '*MASKED*'}) | ||
# <values><variable><id>ssid</id><value>MY_SSID</value></variable></values> | ||
for key in keys: | ||
values = tree.xpath(f"/values/variable[id/text()='{key}']/value") | ||
for v in values: | ||
v.text = '*MASKED*' | ||
|
||
return scrubbed_values | ||
return etree.tostring(tree) |
Oops, something went wrong.