From c3e9bd1444c1d73fb03c09535af364370a86d915 Mon Sep 17 00:00:00 2001 From: Tyler Page Date: Fri, 11 Jan 2019 07:48:36 +0000 Subject: [PATCH] Change state() to try/except to catch KeyError (#19935) * Change state() to try/except to catch KeyError When Tautulli is up but Plex is down, the API doesn't return a 'stream_count' key. This causes calls to state() to raise KeyError exceptions. The new code includes a try/except to catch the KeyError and return -1 signifying that the Tautulli API cannot talk to Plex * Update tautulli.py --- homeassistant/components/sensor/tautulli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/tautulli.py b/homeassistant/components/sensor/tautulli.py index aa651a9ab1a..5c48731f7df 100644 --- a/homeassistant/components/sensor/tautulli.py +++ b/homeassistant/components/sensor/tautulli.py @@ -119,7 +119,7 @@ class TautulliSensor(Entity): @property def state(self): """Return the state of the sensor.""" - return self.sessions['stream_count'] + return self.sessions.get('stream_count') @property def icon(self):