From a73fbbaf7aab69165ffd2a44cb7750ff5aa671c3 Mon Sep 17 00:00:00 2001 From: hexa- Date: Tue, 22 Nov 2016 04:34:48 +0100 Subject: [PATCH] switch.tplink: expect daily stats to be empty (#4504) Signed-off-by: Martin Weinelt --- homeassistant/components/switch/tplink.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index 0707ee3756b..bcc1b329fa8 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -97,8 +97,12 @@ class SmartPlugSwitch(SwitchDevice): = "%.1f A" % emeter_readings["current"] emeter_statics = self.smartplug.get_emeter_daily() - self._emeter_params[ATTR_DAILY_CONSUMPTION] \ - = "%.2f kW" % emeter_statics[int(time.strftime("%e"))] + try: + self._emeter_params[ATTR_DAILY_CONSUMPTION] \ + = "%.2f kW" % emeter_statics[int(time.strftime("%e"))] + except KeyError: + # device returned no daily history + pass except OSError: _LOGGER.warning('Could not update status for %s', self.name)