Skip to content

Commit

Permalink
Merge branch 'fix_100_humanreadable_pairing_status' into add_bluetooth
Browse files Browse the repository at this point in the history
  • Loading branch information
jlusiardi committed Jan 28, 2019
2 parents 26a3879 + 0613f13 commit 5022f17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
31 changes: 19 additions & 12 deletions homekit/model/status_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@
#


class _StatusFlags(object):
class _IpStatusFlags(object):
"""
Data taken form table 5-9 page 70
"""

def __init__(self):
self._data = {
0: 'paired',
1: 'unpaired'
}

def __getitem__(self, item):
if item in self._data:
return self._data[item]
print(type(item))
raise KeyError('Item {item} not found'.format(item=item))
i = int(item)
result = []
if i & 0x01:
result.append('Accessory has not been paired with any controllers.')
i = i - 0x01
else:
result.append('Accessory has been paired.')
if i & 0x02:
result.append('Accessory has not been configured to join a Wi-Fi network.')
i = i - 0x02
if i & 0x04:
result.append('A problem has been detected on the accessory.')
i = i - 0x04
if i == 0:
return ' '.join(result)
else:
raise KeyError('Item {item} not found'.format(item=item))


StatusFlags = _StatusFlags()
IpStatusFlags = _IpStatusFlags()
4 changes: 2 additions & 2 deletions homekit/zeroconf_impl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from homekit.model import Categories
from homekit.model.feature_flags import FeatureFlags
from homekit.model.status_flags import StatusFlags
from homekit.model.status_flags import IpStatusFlags


class CollectingListener(object):
Expand Down Expand Up @@ -133,7 +133,7 @@ def discover_homekit_devices(max_seconds=10):
sf = get_from_properties(props, b'sf', case_sensitive=False)
if sf:
d['sf'] = sf
d['statusflags'] = StatusFlags[int(sf)]
d['statusflags'] = IpStatusFlags[int(sf)]

ci = get_from_properties(props, b'ci', case_sensitive=False)
if ci:
Expand Down

0 comments on commit 5022f17

Please sign in to comment.