Skip to content

Commit

Permalink
[deconz] enable thing updates for deconz (#83)
Browse files Browse the repository at this point in the history
* enable thing updates for deconz

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
  • Loading branch information
J-N-K authored Apr 29, 2021
1 parent cbde18f commit 83d64f0
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bundles/org.smarthomej.binding.deconz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@

<name>SmartHome/J Add-ons :: Bundles :: deCONZ Binding</name>

<dependencies>
<dependency>
<groupId>org.smarthomej.addons.bundles</groupId>
<artifactId>org.smarthomej.commons</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<feature>openhab-runtime-base</feature>
<feature>openhab-transport-http</feature>
<feature>openhab-transport-upnp</feature>
<bundle dependency="true">mvn:org.smarthomej.addons.bundles/org.smarthomej.commons/${project.version}</bundle>
<bundle start-level="80">mvn:org.smarthomej.addons.bundles/org.smarthomej.binding.deconz/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<channel typeId="scene" id="scene"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:group"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<description>A warning device</description>
<category>Siren</category>
<channels>
<channel id="alert" typeId="alert"></channel>
<channel typeId="alert" id="alert"></channel>
</channels>

<representation-property>uid</representation-property>
Expand Down Expand Up @@ -40,13 +40,19 @@
<supported-bridge-type-refs>
<bridge-type-ref id="deconz"/>
</supported-bridge-type-refs>

<label>On/Off Light</label>
<description>A light that can be turned on or off.</description>

<channels>
<channel typeId="system.power" id="switch"/>
<channel typeId="ontime" id="ontime"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:sensor"/>
Expand All @@ -62,9 +68,13 @@
<channels>
<channel typeId="system.brightness" id="brightness"/>
<channel typeId="ontime" id="ontime"/>
<channel id="alert" typeId="alert"></channel>
<channel typeId="alert" id="alert"></channel>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:light"/>
Expand All @@ -81,9 +91,13 @@
<channel typeId="system.brightness" id="brightness"/>
<channel typeId="ct" id="color_temperature"/>
<channel typeId="ontime" id="ontime"/>
<channel id="alert" typeId="alert"></channel>
<channel typeId="alert" id="alert"></channel>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:light"/>
Expand All @@ -99,9 +113,13 @@
<channels>
<channel typeId="system.color" id="color"/>
<channel typeId="ontime" id="ontime"/>
<channel id="alert" typeId="alert"></channel>
<channel typeId="alert" id="alert"></channel>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:colorlight"/>
Expand All @@ -118,9 +136,13 @@
<channel typeId="system.color" id="color"/>
<channel typeId="ct" id="color_temperature"/>
<channel typeId="ontime" id="ontime"/>
<channel id="alert" typeId="alert"></channel>
<channel typeId="alert" id="alert"></channel>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:colorlight"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<channel typeId="system.power" id="enabled"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:sensor"/>
Expand Down Expand Up @@ -113,6 +117,10 @@
<channel typeId="last_updated" id="last_updated"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:sensor"/>
Expand Down Expand Up @@ -464,6 +472,10 @@
<channel typeId="last_updated" id="last_updated"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
</properties>

<representation-property>uid</representation-property>

<config-description-ref uri="thing-type:deconz:sensor"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the color channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;color,Color,system:color
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the color channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;color,Color,system:color
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the brightness channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;brightness,Dimmer,system:brightness
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the brightness channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;brightness,Dimmer,system:brightness
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the color channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;color,Color,system:color
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the color channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;color,Color,system:color
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# the switch channel changed from a custom type to the system-type
1;UPDATE_CHANNEL;switch,Switch,system:power
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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());
}
});
}
}

0 comments on commit 83d64f0

Please sign in to comment.