Skip to content

Commit

Permalink
Update error handling and debug logging (#327)
Browse files Browse the repository at this point in the history
Fixes #283
Fixes #285
  • Loading branch information
shbatm authored Dec 20, 2022
1 parent ed9ac5d commit 3e3597c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pyisy/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
URL_NETWORK,
URL_RESOURCES,
)
from .exceptions import XML_ERRORS, XML_PARSE_ERROR, ISYResponseParseError
from .exceptions import XML_ERRORS, XML_PARSE_ERROR
from .helpers import value_from_xml


Expand Down Expand Up @@ -64,8 +64,8 @@ def parse(self, xml):
try:
xmldoc = minidom.parseString(xml)
except XML_ERRORS:
_LOGGER.error("%s: NetworkResources", XML_PARSE_ERROR)
raise ISYResponseParseError(XML_PARSE_ERROR)
_LOGGER.error("%s: NetworkResources, resources not loaded", XML_PARSE_ERROR)
return

features = xmldoc.getElementsByTagName(TAG_NET_RULE)
for feature in features:
Expand Down
3 changes: 3 additions & 0 deletions pyisy/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ def parse(self, xml):
# Get Node Information
address = value_from_xml(feature, TAG_ADDRESS)
nname = value_from_xml(feature, TAG_NAME)

_LOGGER.debug("Parsing %s: %s [%s]", ntype, nname, address)

nparent = value_from_xml(feature, TAG_PARENT)
pnode = value_from_xml(feature, TAG_PRIMARY_NODE)
family = value_from_xml(feature, TAG_FAMILY)
Expand Down
9 changes: 6 additions & 3 deletions pyisy/programs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
XML_ON,
XML_TRUE,
)
from ..exceptions import XML_ERRORS, XML_PARSE_ERROR, ISYResponseParseError
from ..exceptions import XML_ERRORS, XML_PARSE_ERROR
from ..helpers import attr_from_element, now, value_from_xml
from ..nodes import NodeIterator as ProgramIterator
from .folder import Folder
Expand Down Expand Up @@ -192,8 +192,8 @@ def parse(self, xml):
try:
xmldoc = minidom.parseString(xml)
except XML_ERRORS:
_LOGGER.error("%s: Programs", XML_PARSE_ERROR)
raise ISYResponseParseError(XML_PARSE_ERROR)
_LOGGER.error("%s: Programs, programs not loaded", XML_PARSE_ERROR)
return

plastup = now()

Expand All @@ -203,6 +203,9 @@ def parse(self, xml):
# id, name, and status
address = attr_from_element(feature, ATTR_ID)
pname = value_from_xml(feature, TAG_NAME)

_LOGGER.debug("Parsing Program/Folder: %s [%s]", pname, address)

pparent = attr_from_element(feature, ATTR_PARENT)
pstatus = attr_from_element(feature, ATTR_STATUS) == XML_TRUE

Expand Down
21 changes: 14 additions & 7 deletions pyisy/variables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ def __init__(
self.vobjs = vobjs
return

valid_definitions = False
if def_xml is not None:
self.parse_definitions(def_xml)
if var_xml is not None:
valid_definitions = self.parse_definitions(def_xml)
if valid_definitions and var_xml is not None:
self.parse(var_xml)
else:
_LOGGER.warning("No valid variables defined")

def __str__(self):
"""Return a string representation of the variable manager."""
Expand All @@ -92,21 +95,25 @@ def __repr__(self):

def parse_definitions(self, xmls):
"""Parse the XML Variable Definitions from the ISY."""
valid_definitions = False
for ind in range(2):
# parse definitions
if xmls[ind] is None or xmls[ind] in EMPTY_VARIABLE_RESPONSES:
# No variables of this type defined.
_LOGGER.info("No Type %s variables defined", ind + 1)
continue
try:
xmldoc = minidom.parseString(xmls[ind])
except XML_ERRORS:
_LOGGER.error("%s: Type %s Variables", XML_PARSE_ERROR, ind + 1)
continue

features = xmldoc.getElementsByTagName(TAG_VARIABLE)
for feature in features:
vid = int(attr_from_element(feature, ATTR_ID))
self.vnames[ind + 1][vid] = attr_from_element(feature, TAG_NAME)
else:
features = xmldoc.getElementsByTagName(TAG_VARIABLE)
for feature in features:
vid = int(attr_from_element(feature, ATTR_ID))
self.vnames[ind + 1][vid] = attr_from_element(feature, TAG_NAME)
valid_definitions = True
return valid_definitions

def parse(self, xml):
"""Parse XML from the controller with details about the variables."""
Expand Down

0 comments on commit 3e3597c

Please sign in to comment.