hthiery / python-fritzhome

Python Library to access AVM Fritz!Box homeautomation
MIT License
52 stars 37 forks source link

Template support raises error for FB running with firmware < 7 #70

Closed tobixx closed 1 year ago

tobixx commented 1 year ago

Templates were introduced in Fritz OS 7, so every older device now hits a Traceback due to not checking the existent of the templates:

File "/usr/src/homeassistant/homeassistant/components/fritzbox/coordinator.py", line 48, in _update_fritz_devices
    self.fritz.update_templates()
  File "/usr/local/lib/python3.10/site-packages/pyfritzhome/fritzhome.py", line 357, in update_templates
    for element in self.get_template_elements():
  File "/usr/local/lib/python3.10/site-packages/pyfritzhome/fritzhome.py", line 371, in get_template_elements
    return self._get_listinfo_elements("template")
  File "/usr/local/lib/python3.10/site-packages/pyfritzhome/fritzhome.py", line 144, in _get_listinfo_elements
    dom = ElementTree.fromstring(plain)
  File "/usr/local/lib/python3.10/xml/etree/ElementTree.py", line 1343, in XML
    return parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

(shorter TB without homeassistant stack in front)

The result of fritz._aha_request("gettemplateinfos") is an empty string in this case.

mib1185 commented 1 year ago

We need a has_template function in Fritzhome class. Maybe by just checking the FritzOS version (templates are available since 6.98) or by trying to gather the templates and if it does not return a valid xml with a templaytelist element, we do not have templates. I've already asked the user in https://github.com/home-assistant/core/issues/83555#issuecomment-1344831069 to provide the outputs of gettemplatelistinfos from abox with <6.98