From 24efda20bf2cc8b68e12a73969a0e39917f2180d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Bedn=C3=A1rik?= Date: Tue, 6 Nov 2018 12:43:47 +0100 Subject: [PATCH] Add additional property to HomeKitSwitch to show whether the Homekit outlet is in use (#17448) * Add additional property to HomeKitSwitch to show whether the Homekit outlet is in use or not * Fix issues from review - Remove unused property, simplify and rename the device_state_attributes method --- .../components/switch/homekit_controller.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/homeassistant/components/switch/homekit_controller.py b/homeassistant/components/switch/homekit_controller.py index 374e59aa77b..6333375b560 100644 --- a/homeassistant/components/switch/homekit_controller.py +++ b/homeassistant/components/switch/homekit_controller.py @@ -12,6 +12,8 @@ from homeassistant.components.switch import SwitchDevice DEPENDENCIES = ['homekit_controller'] +OUTLET_IN_USE = "outlet_in_use" + _LOGGER = logging.getLogger(__name__) @@ -29,6 +31,7 @@ class HomeKitSwitch(HomeKitEntity, SwitchDevice): """Initialise the switch.""" super().__init__(*args) self._on = None + self._outlet_in_use = None def update_characteristics(self, characteristics): """Synchronise the switch state with Home Assistant.""" @@ -42,6 +45,7 @@ class HomeKitSwitch(HomeKitEntity, SwitchDevice): self._on = characteristic['value'] elif ctype == "outlet-in-use": self._chars['outlet-in-use'] = characteristic['iid'] + self._outlet_in_use = characteristic['value'] @property def is_on(self): @@ -62,3 +66,11 @@ class HomeKitSwitch(HomeKitEntity, SwitchDevice): 'iid': self._chars['on'], 'value': False}] self.put_characteristics(characteristics) + + @property + def device_state_attributes(self): + """Return the optional state attributes.""" + if self._outlet_in_use is not None: + return { + OUTLET_IN_USE: self._outlet_in_use, + }