Simplfy homekit_controller characteristic writes (#32683)

This commit is contained in:
Jc2k 2020-03-11 16:27:20 +00:00 committed by GitHub
parent c56530a712
commit ffe8b94d75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 123 additions and 233 deletions

View file

@ -338,12 +338,8 @@ class HKDevice:
async def put_characteristics(self, characteristics):
"""Control a HomeKit device state from Home Assistant."""
chars = []
for row in characteristics:
chars.append((row["aid"], row["iid"], row["value"]))
async with self.pairing_lock:
results = await self.pairing.put_characteristics(chars)
results = await self.pairing.put_characteristics(characteristics)
# Feed characteristics back into HA and update the current state
# results will only contain failures, so anythin in characteristics
@ -351,8 +347,8 @@ class HKDevice:
# reflect the change immediately.
new_entity_state = {}
for row in characteristics:
key = (row["aid"], row["iid"])
for aid, iid, value in characteristics:
key = (aid, iid)
# If the key was returned by put_characteristics() then the
# change didn't work
@ -361,7 +357,7 @@ class HKDevice:
# Otherwise it was accepted and we can apply the change to
# our state
new_entity_state[key] = {"value": row["value"]}
new_entity_state[key] = {"value": value}
self.process_new_events(new_entity_state)