Add an asyncio Lock around pairing, which cant be used concurrently (#21933)

This commit is contained in:
Jc2k 2019-03-11 18:59:41 +00:00 committed by Paulus Schoutsen
parent 4f5446ff02
commit 5e2302e469
7 changed files with 76 additions and 63 deletions

View file

@ -75,20 +75,20 @@ class HomeKitLock(HomeKitEntity, LockDevice):
"""Return True if entity is available."""
return self._state is not None
def lock(self, **kwargs):
async def async_lock(self, **kwargs):
"""Lock the device."""
self._set_lock_state(STATE_LOCKED)
await self._set_lock_state(STATE_LOCKED)
def unlock(self, **kwargs):
async def async_unlock(self, **kwargs):
"""Unlock the device."""
self._set_lock_state(STATE_UNLOCKED)
await self._set_lock_state(STATE_UNLOCKED)
def _set_lock_state(self, state):
async def _set_lock_state(self, state):
"""Send state command."""
characteristics = [{'aid': self._aid,
'iid': self._chars['lock-mechanism.target-state'],
'value': TARGET_STATE_MAP[state]}]
self.put_characteristics(characteristics)
await self._accessory.put_characteristics(characteristics)
@property
def device_state_attributes(self):