Skip to content

Commit

Permalink
Fixed error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jxlarrea authored Aug 16, 2019
1 parent 61f8382 commit d5c9738
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions custom_components/ha-emfitqs/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
sensors.append(EmfitQSBinarySensor(data.data['ser'], data, sensor_type))
add_entities(sensors)
return True
except requests.exceptions.HTTPError as error:
_LOGGER.error(error)
except:
_LOGGER.error("Error ocurred")
return False

class EmfitQSData(object):
Expand All @@ -60,21 +60,25 @@ def __init__(self, host):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
entries = {}
r = requests.get('http://{0}/dvmstatus.htm'.format(self._host))
if r.status_code == 200:
elements = r.text.replace("<br>",'').lower().split('\r\n')
filtered = list(filter(None, elements))
for f in filtered:
entry = f.split("=")
entry_name = entry[0].replace(':', '').replace(' ', '_').replace(',', '')
if entry_name=="pres":
if entry[1]=="0":
entry_value = "off"
try:
r = requests.get('http://{0}/dvmstatus.htm'.format(self._host))
if r.status_code == 200:
elements = r.text.replace("<br>",'').lower().split('\r\n')
filtered = list(filter(None, elements))
for f in filtered:
entry = f.split("=")
entry_name = entry[0].replace(':', '').replace(' ', '_').replace(',', '')
if entry_name=="pres":
if entry[1]=="0":
entry_value = "off"
else:
entry_value = "on"
else:
entry_value = "on"
else:
entry_value = entry[1]
entries[entry_name] = entry_value
entry_value = entry[1]
entries[entry_name] = entry_value
except:
_LOGGER.error("Error ocurred")

self.data = entries
_LOGGER.debug("Data = %s", self.data)

Expand Down Expand Up @@ -102,10 +106,12 @@ def state(self):
return self._state

def update(self):
self.data.update()
data = self.data.data

self._state = data[self._resource]
try:
self.data.update()
data = self.data.data
self._state = data[self._resource]
except:
_LOGGER.error("Error ocurred")

@property
def device_class(self):
Expand Down

0 comments on commit d5c9738

Please sign in to comment.