import org.openhab.binding.nuki.internal.handler.NukiBridgeHandler;
import org.openhab.binding.nuki.internal.handler.NukiOpenerHandler;
import org.openhab.binding.nuki.internal.handler.NukiSmartLockHandler;
-import org.openhab.core.config.core.Configuration;
import org.openhab.core.id.InstanceUUID;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.net.HttpServiceUtil;
return null;
}
- @Override
- protected @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID) {
- return super.createThing(thingTypeUID, configuration, thingUID);
- }
-
@Override
public void removeThing(ThingUID thingUID) {
super.removeThing(thingUID);
responseEntity = new ResponseEntity(HttpStatus.BAD_REQUEST_400,
new NukiHttpServerStatusResponseDto("Invalid BCB-Request!"));
} else {
- responseEntity = doHandle(bridgeApiLockStateRequestDto, request.getParameter("bridgeId"));
+ try {
+ responseEntity = doHandle(bridgeApiLockStateRequestDto);
+ } catch (Exception e) {
+ logger.warn("Error processing request '{}'", gson.toJson(bridgeApiLockStateRequestDto), e);
+ throw e;
+ }
}
setHeaders(response);
response.getWriter().write(gson.toJson(responseEntity.getData()));
}
- private ResponseEntity doHandle(BridgeApiLockStateRequestDto request, @Nullable String bridgeId) {
+ private ResponseEntity doHandle(BridgeApiLockStateRequestDto request) {
String nukiId = request.getNukiId().toString();
for (NukiBridgeHandler nukiBridgeHandler : nukiBridgeHandlers) {
logger.trace("Searching Bridge[{}] with NukiBridgeHandler[{}] for nukiId[{}].",
import org.openhab.binding.nuki.internal.dataexchange.NukiHttpClient;
import org.openhab.binding.nuki.internal.dto.BridgeApiDeviceStateDto;
import org.openhab.binding.nuki.internal.dto.BridgeApiListDeviceDto;
+import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
@Nullable
private NukiHttpClient nukiHttpClient;
+ public AbstractNukiDeviceHandler(Thing thing) {
+ super(thing);
+ this.configuration = getConfigAs(getConfigurationClass());
+ }
+
private static String hexToDecimal(String hexString) {
return String.valueOf(Integer.parseInt(hexString, 16));
}
}
}
- public AbstractNukiDeviceHandler(Thing thing) {
- super(thing);
- this.configuration = getConfigAs(getConfigurationClass());
+ /**
+ * Performs migration of old device configuration
+ *
+ * @return true if configuration was change and reload is needed
+ */
+ protected boolean migrateConfiguration() {
+ String nukiId = getConfig().get(NukiBindingConstants.PROPERTY_NUKI_ID).toString();
// legacy support - check if nukiId is hexadecimal (which might have been set by previous binding version)
// and convert it to decimal
- if (NUKI_ID_HEX_PATTERN.matcher(this.configuration.nukiId).matches()) {
+ if (NUKI_ID_HEX_PATTERN.matcher(nukiId).matches()) {
logger.warn(
"SmartLock '{}' was created by old version of binding. It is recommended to delete it and discover again",
thing.getUID());
- this.thing.getConfiguration().put(NukiBindingConstants.PROPERTY_NUKI_ID,
- hexToDecimal(configuration.nukiId));
- this.configuration = getConfigAs(getConfigurationClass());
+ Configuration newConfig = editConfiguration();
+ newConfig.put(NukiBindingConstants.PROPERTY_NUKI_ID, hexToDecimal(nukiId));
+ updateConfiguration(newConfig);
+ return true;
+ } else {
+ return false;
}
}
@Override
public void initialize() {
+ this.configuration = getConfigAs(getConfigurationClass());
+ if (migrateConfiguration()) {
+ this.configuration = getConfigAs(getConfigurationClass());
+ }
scheduler.execute(this::initializeHandler);
}
import java.time.Duration;
import java.time.Instant;
+import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.nuki.internal.configuration.NukiDeviceConfiguration;
updateState(NukiBindingConstants.CHANNEL_OPENER_RING_ACTION_TIMESTAMP, state.getRingactionTimestamp(),
this::toDateTime);
- if (state.getRingactionState() && Duration.between(lastRingAction, Instant.now()).getSeconds() > 30) {
+ if (Objects.equals(state.getRingactionState(), true)
+ && Duration.between(lastRingAction, Instant.now()).getSeconds() > 30) {
triggerChannel(NukiBindingConstants.CHANNEL_OPENER_RING_ACTION_STATE, NukiBindingConstants.EVENT_RINGING);
lastRingAction = Instant.now();
}
super(thing);
}
- @Override
- public void initialize() {
- super.initialize();
- }
-
@Override
public void refreshState(BridgeApiDeviceStateDto state) {
updateState(NukiBindingConstants.CHANNEL_SMARTLOCK_LOCK,