diff --git a/bundles/org.smarthomej.binding.deconz/pom.xml b/bundles/org.smarthomej.binding.deconz/pom.xml index 714ca0bc34..4e5b512ec8 100644 --- a/bundles/org.smarthomej.binding.deconz/pom.xml +++ b/bundles/org.smarthomej.binding.deconz/pom.xml @@ -14,4 +14,13 @@ SmartHome/J Add-ons :: Bundles :: deCONZ Binding + + + org.smarthomej.addons.bundles + org.smarthomej.commons + ${project.version} + provided + + + diff --git a/bundles/org.smarthomej.binding.deconz/src/main/feature/feature.xml b/bundles/org.smarthomej.binding.deconz/src/main/feature/feature.xml index 103e04071a..d6ecb14753 100644 --- a/bundles/org.smarthomej.binding.deconz/src/main/feature/feature.xml +++ b/bundles/org.smarthomej.binding.deconz/src/main/feature/feature.xml @@ -6,6 +6,7 @@ openhab-runtime-base openhab-transport-http openhab-transport-upnp + mvn:org.smarthomej.addons.bundles/org.smarthomej.commons/${project.version} mvn:org.smarthomej.addons.bundles/org.smarthomej.binding.deconz/${project.version} diff --git a/bundles/org.smarthomej.binding.deconz/src/main/java/org/smarthomej/binding/deconz/internal/handler/DeconzBaseThingHandler.java b/bundles/org.smarthomej.binding.deconz/src/main/java/org/smarthomej/binding/deconz/internal/handler/DeconzBaseThingHandler.java index d58029c423..9ed161cf5a 100644 --- a/bundles/org.smarthomej.binding.deconz/src/main/java/org/smarthomej/binding/deconz/internal/handler/DeconzBaseThingHandler.java +++ b/bundles/org.smarthomej.binding.deconz/src/main/java/org/smarthomej/binding/deconz/internal/handler/DeconzBaseThingHandler.java @@ -31,7 +31,6 @@ import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.ThingStatusInfo; -import org.openhab.core.thing.binding.BaseThingHandler; import org.openhab.core.thing.binding.builder.ChannelBuilder; import org.openhab.core.thing.binding.builder.ThingBuilder; import org.openhab.core.thing.type.ChannelKind; @@ -44,6 +43,7 @@ import org.smarthomej.binding.deconz.internal.netutils.WebSocketConnection; import org.smarthomej.binding.deconz.internal.netutils.WebSocketMessageListener; import org.smarthomej.binding.deconz.internal.types.ResourceType; +import org.smarthomej.commons.UpdatingBaseThingHandler; import com.google.gson.Gson; @@ -57,7 +57,7 @@ * @author Jan N. Klug - Refactored to abstract class */ @NonNullByDefault -public abstract class DeconzBaseThingHandler extends BaseThingHandler implements WebSocketMessageListener { +public abstract class DeconzBaseThingHandler extends UpdatingBaseThingHandler implements WebSocketMessageListener { private final Logger logger = LoggerFactory.getLogger(DeconzBaseThingHandler.class); protected final ResourceType resourceType; protected ThingConfig config = new ThingConfig(); diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml index 67a583e604..7a09e820e2 100644 --- a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/group-thing-types.xml @@ -19,6 +19,10 @@ + + 1 + + uid diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml index 1e125605d3..3236409b64 100644 --- a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/light-thing-types.xml @@ -12,7 +12,7 @@ A warning device Siren - + uid @@ -40,13 +40,19 @@ + A light that can be turned on or off. + + + 1 + + uid @@ -62,9 +68,13 @@ - + + + 1 + + uid @@ -81,9 +91,13 @@ - + + + 1 + + uid @@ -99,9 +113,13 @@ - + + + 1 + + uid @@ -118,9 +136,13 @@ - + + + 1 + + uid diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/sensor-thing-types.xml b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/sensor-thing-types.xml index a487c54548..07a4e251da 100644 --- a/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/sensor-thing-types.xml +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/OH-INF/thing/sensor-thing-types.xml @@ -16,6 +16,10 @@ + + 1 + + uid @@ -113,6 +117,10 @@ + + 1 + + uid @@ -464,6 +472,10 @@ + + 1 + + uid diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/batterysensor.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/batterysensor.update new file mode 100644 index 0000000000..ff290a4a9b --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/batterysensor.update @@ -0,0 +1,2 @@ +# the battery_level channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;battery_level,Number,system:battery-level diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorcontrol.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorcontrol.update new file mode 100644 index 0000000000..be4d198a0a --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorcontrol.update @@ -0,0 +1,2 @@ +# the color channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;color,Color,system:color diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorlight.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorlight.update new file mode 100644 index 0000000000..be4d198a0a --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colorlight.update @@ -0,0 +1,2 @@ +# the color channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;color,Color,system:color diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colortemperaturelight.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colortemperaturelight.update new file mode 100644 index 0000000000..7a2a8dde1e --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/colortemperaturelight.update @@ -0,0 +1,2 @@ +# the brightness channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;brightness,Dimmer,system:brightness diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/dimmablelight.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/dimmablelight.update new file mode 100644 index 0000000000..7a2a8dde1e --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/dimmablelight.update @@ -0,0 +1,2 @@ +# the brightness channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;brightness,Dimmer,system:brightness diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/extendedcolorlight.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/extendedcolorlight.update new file mode 100644 index 0000000000..be4d198a0a --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/extendedcolorlight.update @@ -0,0 +1,2 @@ +# the color channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;color,Color,system:color diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/lightgroup.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/lightgroup.update new file mode 100644 index 0000000000..be4d198a0a --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/lightgroup.update @@ -0,0 +1,2 @@ +# the color channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;color,Color,system:color diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/onofflight.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/onofflight.update new file mode 100644 index 0000000000..bb586f2b49 --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/onofflight.update @@ -0,0 +1,2 @@ +# the switch channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;switch,Switch,system:power \ No newline at end of file diff --git a/bundles/org.smarthomej.binding.deconz/src/main/resources/update/presencesensor.update b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/presencesensor.update new file mode 100644 index 0000000000..352867fb70 --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/main/resources/update/presencesensor.update @@ -0,0 +1,3 @@ +# the presence channel and enabled channel changed from a custom type to the system-type +1;UPDATE_CHANNEL;presence,Switch,system:motion +1;UPDATE_CHANNEL;enabled,Switch,system:power diff --git a/bundles/org.smarthomej.binding.deconz/src/test/java/org/smarthomej/binding/deconz/UpdateFileTest.java b/bundles/org.smarthomej.binding.deconz/src/test/java/org/smarthomej/binding/deconz/UpdateFileTest.java new file mode 100644 index 0000000000..5c2b6dbc76 --- /dev/null +++ b/bundles/org.smarthomej.binding.deconz/src/test/java/org/smarthomej/binding/deconz/UpdateFileTest.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2021 Contributors to the SmartHome/J project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.smarthomej.binding.deconz; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.regex.Pattern; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.jupiter.api.Test; +import org.smarthomej.binding.deconz.internal.DeconzHandlerFactory; + +/** + * This class provides tests for automatic thing updates. + * It should be moved to SAT sometime instead of implementing it in every binding + * + * @author Jan N. Klug - Initial contribution + */ +@NonNullByDefault +public class UpdateFileTest { + private static final Pattern VALID_LINES = Pattern + .compile("^(\\d+;(ADD_CHANNEL|UPDATE_CHANNEL|REMOVE_CHANNEL);.*|#.*)$"); + + @Test + public void doCheck() { + checkUpdateFiles(DeconzHandlerFactory.class); + } + + private void checkUpdateFiles(Class clazz) { + // list all files + String path = clazz.getProtectionDomain().getCodeSource().getLocation().getFile() + "update"; + File[] allUpdateFiles = new File(path).listFiles(pathname -> { + if (pathname == null) { + return false; + } + return pathname.getName().endsWith(".update"); + }); + if (allUpdateFiles == null) { + // no updates + return; + } + + // check each file + Arrays.stream(allUpdateFiles).forEach(file -> { + try { + // check each line if it matches the pattern + Files.lines(file.toPath()).forEach(line -> assertEquals(true, VALID_LINES.matcher(line).matches(), + "Checking " + file.getName() + " failed: " + line)); + } catch (IOException e) { + fail("Failed to read" + file.getName()); + } + }); + } +}