Skip to content

Commit 7309ce6

Browse files
authored
Update __init__.py
Adding exception handling in refresh_sensorpush_data to avoid long errors in log when refresh fails
1 parent 1bf73f3 commit 7309ce6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

custom_components/sensorpush/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@ def refresh_sensorpush_data(event_time):
9191
#hass.data[SENSORPUSH_SERVICE].update(update_devices=True)
9292

9393
# retrieve the latest samples from the SensorPush cloud service
94-
latest_samples = hass.data[SENSORPUSH_SERVICE].samples()
95-
if latest_samples:
96-
hass.data[SENSORPUSH_SAMPLES] = latest_samples
97-
98-
# notify all listeners (sensor entities) that they may have new data
99-
dispatcher_send(hass, SIGNAL_SENSORPUSH_UPDATED)
100-
else:
101-
LOG.warn("Unable to fetch latest samples from SensorPush cloud")
94+
try:
95+
latest_samples = hass.data[SENSORPUSH_SERVICE].samples()
96+
if latest_samples:
97+
hass.data[SENSORPUSH_SAMPLES] = latest_samples
98+
99+
# notify all listeners (sensor entities) that they may have new data
100+
dispatcher_send(hass, SIGNAL_SENSORPUSH_UPDATED)
101+
else:
102+
LOG.warn("Unable to fetch latest samples from SensorPush cloud")
103+
except Exception as ex:
104+
LOG.warn(f"Unable to fetch latest samples from SensorPush cloud. Error: {ex}")
102105

103106
# subscribe for notifications that an update should be triggered
104107
hass.services.register(SENSORPUSH_DOMAIN, 'update', refresh_sensorpush_data)

0 commit comments

Comments
 (0)