Skip to content

Commit

Permalink
Handle case of no vars correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkahn committed Jan 16, 2021
1 parent 041e905 commit 27267c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions console.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python -u
"""
Copyright 2016, 2017, 2018, 2019, 2020 Kevin Kahn
Copyright 2016, 2017, 2018, 2019, 2020, 2021 Kevin Kahn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -342,7 +342,7 @@ def LogBadParams(section, name):
cgitb.enable(format='text')
logsupport.Logs.Log(u"Soft ISY Console")

logsupport.Logs.Log(u" \u00A9 Kevin Kahn 2016, 2017, 2018, 2019, 2020")
logsupport.Logs.Log(u" \u00A9 Kevin Kahn 2016, 2017, 2018, 2019, 2020, 2021")
logsupport.Logs.Log("Software under Apache 2.0 License")
logsupport.Logs.Log("Version Information:")
logsupport.Logs.Log(" Running under Python: ", sys.version)
Expand Down
28 changes: 21 additions & 7 deletions hubs/isy/isy.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,18 +489,28 @@ def __init__(self, name, isyaddr, user, pwd, version):
Get the variables
"""
while True:
intgood = True
statgood = True
# noinspection PyBroadException
try:
historybuffer.HBNet.Entry('ISY vars get')

r1 = self.ISYrequestsession.get(self.ISYprefix + 'vars/definitions/2', verify=False, timeout=5)
r2 = self.ISYrequestsession.get(self.ISYprefix + 'vars/definitions/1', verify=False, timeout=5)
historybuffer.HBNet.Entry('ISY vars get done')
# for some reason var reads seem to typically take longer to complete so to at 5 sec
if r1.status_code != 200 or r2.status_code != 200:
logsupport.Logs.Log("Bad ISY var read" + r1.text + r2.text, severity=ConsoleWarning)
# if r1.status_code == 200 and r2.status_code == 200: # good reads for both
# break
if r1.status_code != 200 and 'Not Found' in r1.text: # no state vars
statgood = False
elif r1.status_code != 200:
logsupport.Logs.Log("Bad ISY state var read" + r1.text + r2.text, severity=ConsoleWarning)
raise requests.exceptions.ConnectionError # fake connection error on bad read

if r2.status_code != 200 and 'Not Found' in r2.text: # no int vars
intgood = False
elif r2.status_code != 200:
logsupport.Logs.Log("Bad ISY int var read" + r1.text + r2.text, severity=ConsoleWarning)
raise requests.exceptions.ConnectionError # fake connection error on bad read
logsupport.Logs.Log(
'{}: Successful variable read: {}/{}'.format(self.name, r1.status_code, r2.status_code))
break
except:
# after total power outage ISY is slower to come back than RPi so we wait testing periodically
Expand All @@ -513,10 +523,14 @@ def __init__(self, name, isyaddr, user, pwd, version):
logsupport.Logs.Log('No ISY response restart (vars)')
raise HubInitError

logsupport.Logs.Log(
'{}: Successful variable read: {}/{} ({}/{})'.format(self.name, r1.status_code, r2.status_code, statgood,
intgood))

self.Vars = valuestore.NewValueStore(isyvarssupport.ISYVars(self))
# noinspection PyBroadException
try:
configdictS = xmltodict.parse(r1.text)['CList']['e'] # is a list of vars
configdictS = [] if not statgood else xmltodict.parse(r1.text)['CList']['e'] # is a list of vars
if debug.dbgStore.GetVal('ISYLoad'):
configdictS = xmltodict.parse(x3)['CList']['e']
if debug.dbgStore.GetVal('ISYDump'):
Expand All @@ -530,7 +544,7 @@ def __init__(self, name, isyaddr, user, pwd, version):
logsupport.Logs.Log('No state variables defined')
# noinspection PyBroadException
try:
configdictI = xmltodict.parse(r2.text)['CList']['e']
configdictI = [] if not intgood else xmltodict.parse(r2.text)['CList']['e']
if debug.dbgStore.GetVal('ISYLoad'):
configdictI = xmltodict.parse(x4)['CList']['e']
if debug.dbgStore.GetVal('ISYDump'):
Expand Down

0 comments on commit 27267c4

Please sign in to comment.