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
This commit is contained in:
parent
3322fee814
commit
24efda20bf
1 changed files with 12 additions and 0 deletions
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue