[unifi] Fix thing configuration reload after changes (#11411)

* Fix config reload after changes.

Fixes #11407

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Don't try to initialize client when bridge is offline.

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
jlaur 2021-10-23 00:05:16 +02:00 committed by GitHub
parent d4c9d6ef77
commit 8337f8b92d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 9 deletions

View File

@ -59,6 +59,7 @@ public abstract class UniFiBaseThingHandler<E, C> extends BaseThingHandler {
} }
if (bridge.getStatus() == OFFLINE) { if (bridge.getStatus() == OFFLINE) {
updateStatus(OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "The UniFi Controller is currently offline."); updateStatus(OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "The UniFi Controller is currently offline.");
return;
} }
// mgb: derive the config class from the generic type // mgb: derive the config class from the generic type
Class<?> clazz = (Class<?>) (((ParameterizedType) getClass().getGenericSuperclass()) Class<?> clazz = (Class<?>) (((ParameterizedType) getClass().getGenericSuperclass())

View File

@ -69,16 +69,14 @@ public class UniFiClientThingHandler extends UniFiBaseThingHandler<UniFiClient,
@Override @Override
protected synchronized void initialize(UniFiClientThingConfig config) { protected synchronized void initialize(UniFiClientThingConfig config) {
// mgb: called when the config changes // mgb: called when the config changes
if (thing.getStatus() == INITIALIZING) { logger.debug("Initializing the UniFi Client Handler with config = {}", config);
logger.debug("Initializing the UniFi Client Handler with config = {}", config); if (!config.isValid()) {
if (!config.isValid()) { updateStatus(OFFLINE, CONFIGURATION_ERROR,
updateStatus(OFFLINE, CONFIGURATION_ERROR, "You must define a MAC address, IP address, hostname or alias for this thing.");
"You must define a MAC address, IP address, hostname or alias for this thing."); return;
return;
}
this.config = config;
updateStatus(ONLINE);
} }
this.config = config;
updateStatus(ONLINE);
} }
private static boolean belongsToSite(UniFiClient client, String siteName) { private static boolean belongsToSite(UniFiClient client, String siteName) {