mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 23:22:02 +01:00
[homekit] Simplify start level handling (#13914)
Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
parent
3ea004ad35
commit
260f58904f
@ -107,7 +107,8 @@ public class HomekitImpl implements Homekit, NetworkAddressChangeListener, Ready
|
|||||||
this.metadataRegistry = metadataRegistry;
|
this.metadataRegistry = metadataRegistry;
|
||||||
this.readyService = readyService;
|
this.readyService = readyService;
|
||||||
networkAddressService.addNetworkAddressChangeListener(this);
|
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) {
|
private HomekitSettings processConfig(Map<String, Object> properties) {
|
||||||
@ -152,8 +153,9 @@ public class HomekitImpl implements Homekit, NetworkAddressChangeListener, Ready
|
|||||||
try {
|
try {
|
||||||
HomekitSettings oldSettings = settings;
|
HomekitSettings oldSettings = settings;
|
||||||
settings = processConfig(config);
|
settings = processConfig(config);
|
||||||
if ((oldSettings == null) || (settings == null))
|
if ((oldSettings == null) || (settings == null)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (!oldSettings.name.equals(settings.name) || !oldSettings.pin.equals(settings.pin)
|
if (!oldSettings.name.equals(settings.name) || !oldSettings.pin.equals(settings.pin)
|
||||||
|| !oldSettings.setupId.equals(settings.setupId)
|
|| !oldSettings.setupId.equals(settings.setupId)
|
||||||
|| (oldSettings.networkInterface != null
|
|| (oldSettings.networkInterface != null
|
||||||
@ -177,33 +179,17 @@ public class HomekitImpl implements Homekit, NetworkAddressChangeListener, Ready
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onReadyMarkerAdded(ReadyMarker readyMarker) {
|
public synchronized void onReadyMarkerAdded(ReadyMarker readyMarker) {
|
||||||
int newLevel = Integer.parseInt(readyMarker.getIdentifier());
|
|
||||||
currentStartLevel = newLevel;
|
|
||||||
|
|
||||||
if (newLevel >= StartLevelService.STARTLEVEL_STATES) {
|
|
||||||
try {
|
try {
|
||||||
startHomekitServer();
|
startHomekitServer();
|
||||||
} catch (IOException | InvalidAlgorithmParameterException e) {
|
} catch (IOException | InvalidAlgorithmParameterException e) {
|
||||||
logger.warn("could not initialize HomeKit bridge: {}", e.getMessage());
|
logger.warn("could not initialize HomeKit bridge: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("PMD.EmptyWhileStmt")
|
|
||||||
public synchronized void onReadyMarkerRemoved(ReadyMarker readyMarker) {
|
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,
|
private HomekitRoot startBridge(HomekitServer homekitServer, HomekitAuthInfoImpl authInfo,
|
||||||
HomekitChangeListener changeListener, int instance) throws IOException {
|
HomekitChangeListener changeListener, int instance) throws IOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user