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

[homekit] Simplify start level handling #13914

Merged
merged 1 commit into from
Dec 11, 2022
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public HomekitImpl(@Reference StorageService storageService, @Reference ItemRegi
this.metadataRegistry = metadataRegistry;
this.readyService = readyService;
networkAddressService.addNetworkAddressChangeListener(this);
readyService.registerTracker(this, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE));
readyService.registerTracker(this, new ReadyMarkerFilter().withType(StartLevelService.STARTLEVEL_MARKER_TYPE)
.withIdentifier(Integer.toString(StartLevelService.STARTLEVEL_STATES)));
}

private HomekitSettings processConfig(Map<String, Object> properties) {
Expand Down Expand Up @@ -152,8 +153,9 @@ protected synchronized void modified(Map<String, Object> config) {
try {
HomekitSettings oldSettings = settings;
settings = processConfig(config);
if ((oldSettings == null) || (settings == null))
if ((oldSettings == null) || (settings == null)) {
return;
}
if (!oldSettings.name.equals(settings.name) || !oldSettings.pin.equals(settings.pin)
|| !oldSettings.setupId.equals(settings.setupId)
|| (oldSettings.networkInterface != null
Expand All @@ -177,32 +179,16 @@ protected synchronized void modified(Map<String, Object> config) {

@Override
public synchronized void onReadyMarkerAdded(ReadyMarker readyMarker) {
int newLevel = Integer.parseInt(readyMarker.getIdentifier());
currentStartLevel = newLevel;

if (newLevel >= StartLevelService.STARTLEVEL_STATES) {
try {
startHomekitServer();
} catch (IOException | InvalidAlgorithmParameterException e) {
logger.warn("could not initialize HomeKit bridge: {}", e.getMessage());
}
try {
startHomekitServer();
} catch (IOException | InvalidAlgorithmParameterException e) {
logger.warn("could not initialize HomeKit bridge: {}", e.getMessage());
}
}

@Override
@SuppressWarnings("PMD.EmptyWhileStmt")
public synchronized void onReadyMarkerRemoved(ReadyMarker readyMarker) {
int newLevel = Integer.parseInt(readyMarker.getIdentifier());

if (currentStartLevel > newLevel) {
while (newLevel-- > 0 && !readyService
.isReady(new ReadyMarker(StartLevelService.STARTLEVEL_MARKER_TYPE, Integer.toString(newLevel)))) {
}
currentStartLevel = newLevel;
if (currentStartLevel < StartLevelService.STARTLEVEL_STATES) {
stopHomekitServer();
}
}
stopHomekitServer();
}

private HomekitRoot startBridge(HomekitServer homekitServer, HomekitAuthInfoImpl authInfo,
Expand Down