From 62f5c02b53f3a78caa0a05338f11c4a7ccadda9a Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Mon, 4 Dec 2017 00:15:09 +0000 Subject: [PATCH 1/2] Report availability of TP-Link smart sockets --- homeassistant/components/switch/tplink.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index 8fa6493862c652..eb88fc120bdb9a 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -47,6 +47,7 @@ def __init__(self, smartplug, name): self.smartplug = smartplug self._name = name self._state = None + self._available = True # Set up emeter cache self._emeter_params = {} @@ -55,6 +56,11 @@ def name(self): """Return the name of the Smart Plug, if any.""" return self._name + @property + def available(self) -> bool: + """Return if switch is available.""" + return self._available + @property def is_on(self): """Return true if switch is on.""" @@ -77,6 +83,7 @@ def update(self): """Update the TP-Link switch's state.""" from pyHS100 import SmartDeviceException try: + self._available = True self._state = self.smartplug.state == \ self.smartplug.SWITCH_STATE_ON @@ -105,3 +112,4 @@ def update(self): except (SmartDeviceException, OSError) as ex: _LOGGER.warning('Could not read state for %s: %s', self.name, ex) + self._available = False From 3caa9dbaf7eb5b5e50ccf8123f6603b8eabd9887 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 4 Dec 2017 07:56:49 +0100 Subject: [PATCH 2/2] Changes according to our style guide --- homeassistant/components/switch/tplink.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index eb88fc120bdb9a..6e8c1a6b9bb933 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -5,7 +5,6 @@ https://home-assistant.io/components/switch.tplink/ """ import logging - import time import voluptuous as vol @@ -107,9 +106,9 @@ def update(self): self._emeter_params[ATTR_DAILY_CONSUMPTION] \ = "%.2f kW" % emeter_statics[int(time.strftime("%e"))] except KeyError: - # device returned no daily history + # Device returned no daily history pass except (SmartDeviceException, OSError) as ex: - _LOGGER.warning('Could not read state for %s: %s', self.name, ex) + _LOGGER.warning("Could not read state for %s: %s", self.name, ex) self._available = False