switch.tplink: expect daily stats to be empty (#4504)

Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
This commit is contained in:
hexa- 2016-11-22 04:34:48 +01:00 committed by Paulus Schoutsen
parent 835577b2bc
commit a73fbbaf7a

View file

@ -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)