Skip to content

Conversation

@gbrooker
Copy link
Contributor

Split out from PR #59

When removing pairing, only change sate when no more pairings remain.

Add unpairFromAllControllers() function to remove all pairings.

@gbrooker gbrooker mentioned this pull request Nov 11, 2018

// Remove all the pairings made with this Device
// Can be used in the event of a stale configuration file
public func unpairFromAllControllers() {
Copy link
Owner

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?

Suggested change
public func unpairFromAllControllers() {
public func removeAllPairings() {

Copy link
Contributor Author

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.

logger.debug("Before unpair")
logger.debug(self.configuration)
logger.debug(self.config)
server?.stop()
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need to close all open connections, to force the unpairing.

Copy link
Owner

Choose a reason for hiding this comment

The 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 server?.start(). The documentation would have to be more explicit about what this method does. E.g. should it start() when it wasn't already started on entry, or would that be an invalid entry state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

// 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")
Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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("Before unpair")
logger.debug(self.configuration)
logger.debug(self.config)
server?.stop()
Copy link
Owner

Choose a reason for hiding this comment

The 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 server?.start(). The documentation would have to be more explicit about what this method does. E.g. should it start() when it wasn't already started on entry, or would that be an invalid entry state?

@Bouke Bouke merged commit 8bf2839 into Bouke:master Nov 23, 2018
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

Successfully merging this pull request may close these issues.

2 participants