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

Sixth added accessory to a bridge does not work?! #61

Closed
gerswin opened this issue Mar 19, 2018 · 7 comments
Closed

Sixth added accessory to a bridge does not work?! #61

gerswin opened this issue Mar 19, 2018 · 7 comments
Assignees

Comments

@gerswin
Copy link

gerswin commented Mar 19, 2018

i have 10 lightbulbs devices but for some reason one or two of them randomly gets not supported.

@ikalchev
Copy link
Owner

Does the problem disappear after a restart of HAP-python?

@gerswin
Copy link
Author

gerswin commented Mar 19, 2018

no :/

@ikalchev
Copy link
Owner

Let me try to reproduce and I will get back to you soon.

@ikalchev ikalchev changed the title not supported Sixth added accessory to a bridge does not work?! Mar 20, 2018
@ikalchev ikalchev self-assigned this Mar 20, 2018
@ikalchev
Copy link
Owner

I know this will sound crazy but here it is:

for x in range(0, 13):
    bridge.add_accessory(LightBulb("l%d" % x))

The above adds all accessories and everything works fine. Except the sixth lightbulb with name l5. So I split the above for loop and skipped number 5 (because why not). This time l6 does not work. So I need to investigate why this happens but I think its something silly.

@ikalchev
Copy link
Owner

The above can be reproduced with the loop running in (0, 6).

@ikalchev
Copy link
Owner

I found a workaround:

for x in range(0, 6):
    bridge.add_accessory(LightBulb("l%d" % x), 100 + x)

The code in add_accessory assigns AIDs from 2 onwards. For some reason, AID=7 gets unsupported. I tried to reproduce the error with a different AID by adding twice the number of accessories - nothing. When I start assigning AIDs from 100 instead (as in the code above), everything works like a charm.

I really have no idea why this happens. At first I thought that maybe AIDs should not be the same as IIDs of services (in this case IID=7 is the iid of the lightbulb service), but this is not true since I tried to reproduce the problem with different combination of IID and AID. In those other cases, even if the service IID is the same as the AID, the Acc is supported and works.

I will make a change that just assigns AIDs from some higher number, at least until we find why this happens.

ikalchev added a commit that referenced this issue Mar 25, 2018
For some reason, this AID results in "Not supported" in the Home app.
This happense when you add 6 accessories. Various attempts to reproduce
this issue with other AIDs - using more services, etc., whitout success.
ikalchev added a commit that referenced this issue Mar 25, 2018
@ikalchev
Copy link
Owner

Quoting from the official spec:

Accessory instance IDs, "aid", are assigned from the same number pool that is global across entire HAP Accessory Server. For example, if the first Accessory object has an instance ID of "1" then no other Accessory object can have an instance ID of "1" within the Accessory Server.

What we give to the Home app when it says unsupported:

DEBUG:pyhap.hap_server:Request GET from address '('192.168.1.211', 50079)' for path '/accessories'.
{'aid': 1, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'Bridge'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000062-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000063-0000-1000-8000-0026BB765291', 'description': 'Reachable', 'perms': ['pr', 'ev'], 'format': 'bool', 'value': False}, {'iid': 9, 'type': '0000009C-0000-1000-8000-0026BB765291', 'description': 'LinkQuality', 'perms': ['pr', 'ev'], 'format': 'uint8', 'maxValue': 4, 'minValue': 1, 'minStep': 1, 'value': 1}, {'iid': 10, 'type': '00000057-0000-1000-8000-0026BB765291', 'description': 'AccessoryIdentifier', 'perms': ['pr'], 'format': 'string', 'value': ''}, {'iid': 11, 'type': '000000A3-0000-1000-8000-0026BB765291', 'description': 'Category', 'perms': ['pr', 'ev'], 'format': 'uint16', 'maxValue': 16, 'minValue': 1, 'minStep': 1, 'value': 1}]}]}
{'aid': 2, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l0'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}
{'aid': 3, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l1'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}
{'aid': 4, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l2'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}
{'aid': 5, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l3'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}
{'aid': 6, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l4'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}
{'aid': 7, 'services': [{'iid': 1, 'type': '0000003E-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 2, 'type': '00000014-0000-1000-8000-0026BB765291', 'description': 'Identify', 'perms': ['pw'], 'format': 'bool'}, {'iid': 3, 'type': '00000020-0000-1000-8000-0026BB765291', 'description': 'Manufacturer', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Manufacturer'}, {'iid': 4, 'type': '00000021-0000-1000-8000-0026BB765291', 'description': 'Model', 'perms': ['pr'], 'format': 'string', 'value': 'Default-Model'}, {'iid': 5, 'type': '00000023-0000-1000-8000-0026BB765291', 'description': 'Name', 'perms': ['pr'], 'format': 'string', 'value': 'l5'}, {'iid': 6, 'type': '00000030-0000-1000-8000-0026BB765291', 'description': 'SerialNumber', 'perms': ['pr'], 'format': 'string', 'value': 'Default-SerialNumber'}]}, {'iid': 7, 'type': '00000043-0000-1000-8000-0026BB765291', 'characteristics': [{'iid': 8, 'type': '00000025-0000-1000-8000-0026BB765291', 'description': 'On', 'perms': ['pr', 'pw', 'ev'], 'format': 'bool', 'value': False}]}]}

Submitted a fix that basically does not assign 7 as an AID...

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