Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Sources/HAP/Server/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ 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 removeAllPairings() {
logger.debug("Removing all pairings")
server?.stop()
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

let allPairingIdentifiers = configuration.pairings.keys
for identifier in allPairingIdentifiers {
remove(pairingWithIdentifier: identifier)
}
}

// Add the pairing to the internal DB and notify the change
// to update the Bonjour broadcast
func add(pairing: Pairing) {
Expand All @@ -339,7 +350,7 @@ public class Device {
configuration.pairings = [:]
}
persistConfig()
if pairingState == .paired {
if pairingState == .paired && configuration.pairings.isEmpty {
// swiftlint:disable:next force_try
try! changePairingState(.notPaired)
}
Expand Down