Skip to content

zeroconf error when protocol version not defined #17

Closed

Description

@sberryman

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.

Activity

  1. jlusiardi commented on Apr 30, 2018

    @jlusiardi
    Owner

    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?

  2. sberryman commented on Apr 30, 2018

    @sberryman
    Author

    Wow, thanks for the super quick fix!

  3. jlusiardi commented on Apr 30, 2018

    @jlusiardi
    Owner

    Can we close this?

  4. sberryman commented on Apr 30, 2018

    @sberryman
    Author

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

  5. added a commit that references this issue on Apr 30, 2018
  6. jlusiardi commented on Apr 30, 2018

    @jlusiardi
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions