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

Automatically update pairings data when its stale #72

Open
Jc2k opened this issue Jan 9, 2019 · 5 comments
Open

Automatically update pairings data when its stale #72

Jc2k opened this issue Jan 9, 2019 · 5 comments
Labels
BLE Transport Issues related to BLE based Accessory enhancement Issues related to missing features IP Transport Issues related to IP based Accessory

Comments

@Jc2k
Copy link
Collaborator

Jc2k commented Jan 9, 2019

We remember all the discovered BLE characteristics in the pairing file. Do we need to be able to invalidate that cache? Does this need changes to the controller API or the connections between discovery and the controller?

E.g. It looks like if you upgrade the firmware (which might add new characteristics?) then the CN number in the ManufacturerData would go up. Should we remember the CN in the pairing file and repopulate it on connection if the number has changed?

For reference, 6.4.22 of the spec says:

CN - 8 bits for Configuration Number, with a default starting value of 1. Accessories must increment the config number after a firmware update. This value must have a range of 1-255 and wrap to 1 when it overflows. This value must persist across reboots, power cycles and firmware updates.

@Jc2k Jc2k changed the title Consider 'stability' of characteristics cache Automatically update pairings data when its stale Jan 9, 2019
@Jc2k
Copy link
Collaborator Author

Jc2k commented Jan 9, 2019

Of course if we do that, do we need to make the Controller automatically save the updated pairings data?

@Jc2k
Copy link
Collaborator Author

Jc2k commented Jan 9, 2019

Part of the same logic would be to have a version number for this library too - specifically for the pairing file format code - so that we can detect changes like #71 where we actually want to repopulate the pairing data.

@jlusiardi jlusiardi added enhancement Issues related to missing features IP Transport Issues related to IP based Accessory BLE Transport Issues related to BLE based Accessory labels Jan 10, 2019
@jlusiardi
Copy link
Owner

I think this affects both type of accessories: 6.4.2 of the spec is for BLE where is 5.4 also has c# (configuration number) for IP. For IP, the configuration number

Must update when an accessory, service, or characteristic is added or removed on the accessory
server.
Accessories must increment the config number after a firmware update.

The following steps would be required:

  • upon pairing, also store the CN / C# in the pairing data
  • run discovery from time to time and compare CN / C# from the saved data
  • if it has increased (or wrapped around) perform list_accessories_and_characteristics on the pairing and update the file with the new values

@Jc2k
Copy link
Collaborator Author

Jc2k commented Jan 10, 2019

I think its easier for BLE, as we can easily parse the MfrData from within the scope of a connection to a mac address - we don't have to invoke discovery. I'm unsure about how to approach it for the IP transport though. There was a PR to decouple IP connections from discovery because they were slow.

In the land of home assistant i would be able to pass in the current CN/C# from discovery into get_pairing, and that would avoid having to invoke discovery a 2nd time. That feels kind of dirty, though.

I was going to put together a PR that:

  • Optionally allows a file path to be passed to Controller.
  • Automatically calls load_data and save_data at appropriate times (inside the controller API, rather than as part of the CLI scripts)
  • Stores the CN/C# in the pairing data, and calls list_accessories_ if its changed, during the BLE device connection phase.

I wasn't going to touch IP devices yet - and I think its safe to do them seperately/later as the IP backend always refreshes the pairing data when you call list_accessories_and_chars.

Does that sound acceptable?

@jlusiardi
Copy link
Owner

yes sounds like a plan to be considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLE Transport Issues related to BLE based Accessory enhancement Issues related to missing features IP Transport Issues related to IP based Accessory
Projects
None yet
Development

No branches or pull requests

2 participants