-
Notifications
You must be signed in to change notification settings - Fork 53
Fix unpair, to only change state when no pairings remain #63
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,6 +317,22 @@ public class Device { | |
| return pairingState == .paired | ||
| } | ||
|
|
||
| // Remove all the pairings made with this Device | ||
| // Can be used in the event of a stale configuration file | ||
| public func unpairFromAllControllers() { | ||
| logger.debug("Before unpair") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need all this logging including the before and after state? And if so: can we condense these six lines into a single line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logging is not needed at all. I can will remove them. |
||
| logger.debug(self.configuration) | ||
| logger.debug(self.config) | ||
| server?.stop() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we stop the server? It's also not clear from the method name that this happens.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we need to close all open connections, to force the unpairing.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So what's the exact use-case of this method? I'm guessing it would be some software equivalent of a hardware device's "hard reset". And so, I would expect it to also call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the use case is part of a local reset. I have removed the server.stop(), as you are right that it is misplaced here. The management of the server state should be performed by the caller. |
||
| let allPairingIdentifiers = configuration.pairings.keys | ||
| for identifier in allPairingIdentifiers { | ||
| remove(pairingWithIdentifier: identifier) | ||
| } | ||
| logger.debug("After unpair") | ||
| logger.debug(self.configuration) | ||
| logger.debug(self.config) | ||
| } | ||
|
|
||
| // Add the pairing to the internal DB and notify the change | ||
| // to update the Bonjour broadcast | ||
| func add(pairing: Pairing) { | ||
|
|
@@ -339,7 +355,7 @@ public class Device { | |
| configuration.pairings = [:] | ||
| } | ||
| persistConfig() | ||
| if pairingState == .paired { | ||
| if pairingState == .paired && configuration.pairings.isEmpty { | ||
| // swiftlint:disable:next force_try | ||
| try! changePairingState(.notPaired) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't notify the other party of the removal, so is it really unpairing or removing the pairing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the HAP protocol doesn't seem to allow for an accessory to request to unpair. The only way to do it is equivalent to a hard reset on a hardware device, i.e to simply close all open connections and forget the pairings. I'll change the function name to your suggestion.