Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zeroconf error when protocol version not defined #17

Closed
sberryman opened this issue Apr 30, 2018 · 5 comments
Closed

zeroconf error when protocol version not defined #17

sberryman opened this issue Apr 30, 2018 · 5 comments

Comments

@sberryman
Copy link

Command:
python3 -m homekit.discover

Results:

Properties: {b'ff': b'1', b'ci': b'2', b'id': b'a8:1b:6a:01:d1:bc', b'sf': b'1', b'md': b'Smart Bridge 2', b'c#': b'11', b's#': b'1'}
Name: Smart Bridge 2._hap._tcp.local.
Url: http://192.168.7.37:4548
Configuration number (c#): 11
Feature Flags (ff): Supports Pairing (Flag: 1)
Device ID (id): a8:1b:6a:01:d1:bc
Model Name (md): Smart Bridge 2
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/srv/homeassistant/lib/python3.5/site-packages/homekit/discover.py", line 32, in <module>
    discover_homekit_devices()
  File "/srv/homeassistant/lib/python3.5/site-packages/homekit/zeroconf.py", line 55, in discover_homekit_devices
    print('Protocol Version (pv): {pv}'.format(pv=info.properties[b'pv'].decode()))
KeyError: b'pv'

I added the top print to show the entire contents of info.properties, funny enough all the other devices that show up list a PV.

A simple if b'pv' in info.properties: wrap around that print line solved that particular issue for me.

@jlusiardi
Copy link
Owner

jlusiardi commented Apr 30, 2018

Yes, you are absolutely right. The spec allows to omit the pv key, if the version is 1.0.

I commit the following:

diff --git a/homekit/zeroconf.py b/homekit/zeroconf.py
index 61d99f3..655d250 100644
--- a/homekit/zeroconf.py
+++ b/homekit/zeroconf.py
@@ -51,7 +51,10 @@ def discover_homekit_devices():
         print('Feature Flags (ff): {f} (Flag: {flags})'.format(f=FeatureFlags[flags], flags=flags))
         print('Device ID (id): {id}'.format(id=info.properties[b'id'].decode()))
         print('Model Name (md): {md}'.format(md=info.properties[b'md'].decode()))
-        print('Protocol Version (pv): {pv}'.format(pv=info.properties[b'pv'].decode()))
+        if b'pv' in info.properties:
+            print('Protocol Version (pv): {pv}'.format(pv=info.properties[b'pv'].decode()))
+        else:
+            print('Protocol Version (pv): 1.0 (default, not set in TXT record)')
         print('State Number (s#): {sn}'.format(sn=info.properties[b's#'].decode()))
         print('Status Flags (sf): {sf}'.format(sf=info.properties[b'sf'].decode()))
         category = int(info.properties[b'ci'].decode())

This should fix it as well and display information about pv in all cases.

See bef34f2

A new release of this package will be released to pypi soon.

Which kind of device do you try to access?

@sberryman
Copy link
Author

Wow, thanks for the super quick fix!

@jlusiardi
Copy link
Owner

Can we close this?

@sberryman
Copy link
Author

I don't see it merged into master and pushed to pypi?

jlusiardi added a commit that referenced this issue Apr 30, 2018
@jlusiardi
Copy link
Owner

Sorry, forgot to push to github. Pypi will follow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants