added migrated 2.x add-ons

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-09-21 01:58:32 +02:00
parent bbf1a7fd29
commit 6df6783b60
11662 changed files with 1302875 additions and 11 deletions

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.avmfritz.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,13 @@
This content is produced and maintained by the openHAB project.
* Project home: https://www.openhab.org
== Declared Project Licenses
This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.
== Source Code
https://github.com/openhab/openhab-addons

View File

@@ -0,0 +1,64 @@
-include: ../itest-common.bndrun
Bundle-SymbolicName: ${project.artifactId}
Fragment-Host: org.openhab.binding.avmfritz
-runrequires: bnd.identity;id='org.openhab.binding.avmfritz.tests'
#
# done
#
-runbundles: \
javax.measure.unit-api;version='[1.0.0,1.0.1)',\
org.apache.commons.io;version='[2.2.0,2.2.1)',\
org.apache.commons.lang;version='[2.6.0,2.6.1)',\
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
org.osgi.service.event;version='[1.4.0,1.4.1)',\
osgi.enroute.hamcrest.wrapper;version='[1.3.0,1.3.1)',\
osgi.enroute.junit.wrapper;version='[4.12.0,4.12.1)',\
org.openhab.core;version='[2.5.0,2.5.1)',\
org.openhab.core.config.core;version='[2.5.0,2.5.1)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.objenesis;version='[2.6.0,2.6.1)',\
org.openhab.core.config.discovery;version='[2.5.0,2.5.1)',\
org.openhab.core.io.console;version='[2.5.0,2.5.1)',\
org.openhab.core.thing;version='[2.5.0,2.5.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
org.apache.commons.exec;version='[1.1.0,1.1.1)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.jupnp;version='[2.5.2,2.5.3)',\
org.openhab.core.config.discovery.upnp;version='[2.5.0,2.5.1)',\
org.openhab.core.io.net;version='[2.5.0,2.5.1)',\
org.openhab.core.test;version='[2.5.0,2.5.1)',\
org.eclipse.equinox.event;version='[1.4.300,1.4.301)',\
com.google.gson;version='[2.8.2,2.8.3)',\
org.apache.xbean.bundleutils;version='[4.12.0,4.12.1)',\
org.apache.xbean.finder;version='[4.12.0,4.12.1)',\
org.apache.servicemix.specs.activation-api-1.1;version='[2.9.0,2.9.1)',\
org.apache.servicemix.specs.jaxb-api-2.2;version='[2.9.0,2.9.1)',\
org.apache.servicemix.specs.stax-api-1.2;version='[2.9.0,2.9.1)',\
tec.uom.lib.uom-lib-common;version='[1.0.3,1.0.4)',\
tec.uom.se;version='[1.0.10,1.0.11)',\
org.apache.servicemix.bundles.jaxb-impl;version='[2.2.11,2.2.12)',\
net.bytebuddy.byte-buddy;version='[1.9.10,1.9.11)',\
net.bytebuddy.byte-buddy-agent;version='[1.9.10,1.9.11)',\
org.mockito.mockito-core;version='[3.1.0,3.1.1)',\
org.objectweb.asm;version='[7.1.0,7.1.1)',\
org.objectweb.asm.commons;version='[7.1.0,7.1.1)',\
org.objectweb.asm.tree;version='[7.1.0,7.1.1)',\
org.eclipse.jetty.client;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.http;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.io;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.security;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.server;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.servlet;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.util;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.websocket.api;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.websocket.client;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.websocket.common;version='[9.4.20,9.4.21)',\
org.eclipse.jetty.xml;version='[9.4.20,9.4.21)',\
org.ops4j.pax.web.pax-web-api;version='[7.2.11,7.2.12)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
org.openhab.binding.avmfritz;version='[2.5.9,2.5.10)',\
org.openhab.binding.avmfritz.tests;version='[2.5.9,2.5.10)'

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.avmfritz.tests</artifactId>
<name>openHAB Add-ons :: Integration Tests :: AVM FRITZ! Binding Tests</name>
<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.avmfritz</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openhab.addons.itests</groupId>
<artifactId>org.openhab.addons.reactor.itests</artifactId>
<version>2.5.9-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.avmfritz.tests</artifactId>
<name>openHAB Add-ons :: Integration Tests :: AVM FRITZ! Binding Tests</name>
<dependencies>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.avmfritz</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,839 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB 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.openhab.binding.avmfritz.internal.discovery;
import static org.openhab.core.thing.Thing.*;
import static org.junit.Assert.*;
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
import java.io.StringReader;
import java.util.Collection;
import java.util.Collections;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultFlag;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openhab.binding.avmfritz.internal.dto.AVMFritzBaseModel;
import org.openhab.binding.avmfritz.internal.dto.DeviceListModel;
import org.openhab.binding.avmfritz.internal.handler.AVMFritzThingHandlerOSGiTest;
import org.openhab.binding.avmfritz.internal.util.JAXBUtils;
/**
* Tests for {@link AVMFritzDiscoveryService}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public class AVMFritzDiscoveryServiceOSGiTest extends AVMFritzThingHandlerOSGiTest {
private static final ThingUID BRIGE_THING_ID = new ThingUID("avmfritz:fritzbox:1");
private @Nullable DiscoveryResult discoveryResult;
private @NonNullByDefault({}) AVMFritzDiscoveryService discovery;
private final DiscoveryListener listener = new DiscoveryListener() {
@Override
public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
discoveryResult = null;
}
@Override
public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
discoveryResult = result;
}
@Override
public @Nullable Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp,
@Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) {
return Collections.emptyList();
}
};
@Override
@Before
public void setUp() {
super.setUp();
discovery = new AVMFritzDiscoveryService();
discovery.setThingHandler(bridgeHandler);
discovery.addDiscoveryListener(listener);
}
@After
public void cleanUp() {
discoveryResult = null;
}
@Test
public void correctSupportedTypes() {
assertEquals(12, discovery.getSupportedThingTypes().size());
assertTrue(discovery.getSupportedThingTypes().contains(DECT100_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(DECT200_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(DECT210_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(DECT300_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(DECT301_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(DECT400_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(PL546E_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(COMETDECT_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(HAN_FUN_CONTACT_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(HAN_FUN_SWITCH_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(GROUP_HEATING_THING_TYPE));
assertTrue(discovery.getSupportedThingTypes().contains(GROUP_SWITCH_THING_TYPE));
}
@Test
public void invalidDiscoveryResult() throws JAXBException {
// attribute productname is important for a valid discovery result
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0954669\" id=\"20\" functionbitmask=\"1280\" fwversion=\"03.86\" manufacturer=\"AVM\" productname=\"\">" +
"<present>1</present>" +
"<name>FRITZ!DECT Repeater 100 #5</name>" +
"<temperature>" +
"<celsius>230</celsius>" +
"<offset>0</offset>" +
"</temperature>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNull(discoveryResult);
}
@Test
public void validDECTRepeater100Result() throws JAXBException {
//@formatter:off
final String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0954669\" id=\"20\" functionbitmask=\"1280\" fwversion=\"03.86\" manufacturer=\"AVM\" productname=\"FRITZ!DECT Repeater 100\">" +
"<present>1</present>" +
"<name>FRITZ!DECT Repeater 100 #5</name>" +
"<temperature>" +
"<celsius>230</celsius>" +
"<offset>0</offset>" +
"</temperature>" +
"</device>" +
"</devicelist>";
//@formatter:on
final Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
assertEquals(1, device.getPresent());
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_DECT_Repeater_100:1:087610954669"), discoveryResult.getThingUID());
assertEquals(DECT100_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610954669", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("20", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610954669", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.86", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
final String deviceNotPresentXml = xml.replace("<present>1</present>", "<present>0</present>");
devices = (DeviceListModel) u.unmarshal(new StringReader(deviceNotPresentXml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
device = devices.getDevicelist().get(0);
assertNotNull(device);
assertEquals(0, device.getPresent());
discovery.onDeviceAdded(device);
assertNull(discoveryResult);
}
@Test
public void validDECT200DiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0000434\" id=\"17\" functionbitmask=\"2944\" fwversion=\"03.83\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 200\">" +
"<present>1</present>" +
"<name>FRITZ!DECT 200 #1</name>" +
"<switch>" +
"<state>0</state>" +
"<mode>manuell</mode>" +
"<lock>0</lock>" +
"<devicelock>1</devicelock>" +
"</switch>" +
"<powermeter>" +
"<voltage>232850</voltage>" +
"<power>45</power>" +
"<energy>166</energy>" +
"</powermeter>" +
"<temperature>" +
"<celsius>255</celsius>" +
"<offset>0</offset>" +
"</temperature>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_DECT_200:1:087610000434"), discoveryResult.getThingUID());
assertEquals(DECT200_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610000434", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("17", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610000434", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.83", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validDECT210DiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0000434\" id=\"17\" functionbitmask=\"2944\" fwversion=\"03.83\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 210\">" +
"<present>1</present>" +
"<name>FRITZ!DECT 210 #1</name>" +
"<switch>" +
"<state>0</state>" +
"<mode>manuell</mode>" +
"<lock>0</lock>" +
"<devicelock>1</devicelock>" +
"</switch>" +
"<powermeter>" +
"<voltage>232850</voltage>" +
"<power>45</power>" +
"<energy>166</energy>" +
"</powermeter>" +
"<temperature>" +
"<celsius>255</celsius>" +
"<offset>0</offset>" +
"</temperature>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_DECT_210:1:087610000434"), discoveryResult.getThingUID());
assertEquals(DECT210_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610000434", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("17", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610000434", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.83", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validCometDECTDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0000435\" id=\"18\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"Comet DECT\">" +
"<present>1</present>" +
"<name>Comet DECT #1</name>" +
"<temperature>" +
"<celsius>220</celsius>" +
"<offset>-10</offset>" +
"</temperature>" +
"<hkr>" +
"<tist>44</tist>" +
"<tsoll>42</tsoll>" +
"<absenk>28</absenk>" +
"<komfort>42</komfort>" +
"<lock>0</lock>" +
"<devicelock>0</devicelock>" +
"<errorcode>0</errorcode>" +
"<batterylow>0</batterylow>" +
"<nextchange>" +
"<endperiod>1484341200</endperiod>" +
"<tchange>28</tchange>" +
"</nextchange>" +
"</hkr>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:Comet_DECT:1:087610000435"), discoveryResult.getThingUID());
assertEquals(COMETDECT_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610000435", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("18", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610000435", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.50", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validDECT300DiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0000435\" id=\"18\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 300\">" +
"<present>1</present>" +
"<name>FRITZ!DECT 300 #1</name>" +
"<temperature>" +
"<celsius>220</celsius>" +
"<offset>-10</offset>" +
"</temperature>" +
"<hkr>" +
"<tist>44</tist>" +
"<tsoll>42</tsoll>" +
"<absenk>28</absenk>" +
"<komfort>42</komfort>" +
"<lock>0</lock>" +
"<devicelock>0</devicelock>" +
"<errorcode>0</errorcode>" +
"<batterylow>0</batterylow>" +
"<nextchange>" +
"<endperiod>1484341200</endperiod>" +
"<tchange>28</tchange>" +
"</nextchange>" +
"</hkr>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_DECT_300:1:087610000435"), discoveryResult.getThingUID());
assertEquals(DECT300_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610000435", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("18", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610000435", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.50", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validDECT301DiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"08761 0000435\" id=\"18\" functionbitmask=\"320\" fwversion=\"03.50\" manufacturer=\"AVM\" productname=\"FRITZ!DECT 301\">" +
"<present>1</present>" +
"<name>FRITZ!DECT 301 #1</name>" +
"<temperature>" +
"<celsius>220</celsius>" +
"<offset>-10</offset>" +
"</temperature>" +
"<hkr>" +
"<tist>44</tist>" +
"<tsoll>42</tsoll>" +
"<absenk>28</absenk>" +
"<komfort>42</komfort>" +
"<lock>0</lock>" +
"<devicelock>0</devicelock>" +
"<errorcode>0</errorcode>" +
"<batterylow>0</batterylow>" +
"<nextchange>" +
"<endperiod>1484341200</endperiod>" +
"<tchange>28</tchange>" +
"</nextchange>" +
"</hkr>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_DECT_301:1:087610000435"), discoveryResult.getThingUID());
assertEquals(DECT301_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("087610000435", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("18", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("087610000435", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("03.50", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validPowerline546EDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"5C:49:79:F0:A3:84\" id=\"19\" functionbitmask=\"640\" fwversion=\"06.92\" manufacturer=\"AVM\" productname=\"FRITZ!Powerline 546E\">" +
"<present>1</present>" +
"<name>FRITZ!Powerline 546E #1</name>" +
"<switch>" +
"<state>0</state>" +
"<mode>manuell</mode>" +
"<lock>0</lock>" +
"<devicelock>1</devicelock>" +
"</switch>" +
"<powermeter>" +
"<voltage>232850</voltage>" +
"<power>0</power>" +
"<energy>2087</energy>" +
"</powermeter>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_Powerline_546E:1:5C_49_79_F0_A3_84"), discoveryResult.getThingUID());
assertEquals(PL546E_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("5C:49:79:F0:A3:84", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("19", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("5C:49:79:F0:A3:84", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("06.92", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void invalidHANFUNContactDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11934 0059578\" id=\"406\" functionbitmask=\"1\" fwversion=\"00.00\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #2</name>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNull(discoveryResult);
}
@Test
public void validHANFUNMagneticContactDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11934 0059578-1\" id=\"2000\" functionbitmask=\"8208\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #2: Unit #2</name>" +
"<etsiunitinfo>" +
"<etsideviceid>406</etsideviceid>" +
"<unittype>513</unittype>" +
"<interfaces>256</interfaces>" +
"</etsiunitinfo>" +
"<alert>" +
"<state/>" +
"</alert>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:HAN_FUN_CONTACT:1:119340059578_1"), discoveryResult.getThingUID());
assertEquals(HAN_FUN_CONTACT_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("119340059578-1", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("0x0feb", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("2000", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("119340059578-1", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("0.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validHANFUNOpticalContactDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11934 0059578-1\" id=\"2001\" functionbitmask=\"8208\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #3: Unit #3</name>" +
"<etsiunitinfo>" +
"<etsideviceid>406</etsideviceid>" +
"<unittype>514</unittype>" +
"<interfaces>256</interfaces>" +
"</etsiunitinfo>" +
"<alert>" +
"<state/>" +
"</alert>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:HAN_FUN_CONTACT:1:119340059578_1"), discoveryResult.getThingUID());
assertEquals(HAN_FUN_CONTACT_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("119340059578-1", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("0x0feb", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("2001", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("119340059578-1", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("0.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validHANFUNMotionSensorDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11934 0059578-1\" id=\"2002\" functionbitmask=\"8208\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #3: Unit #3</name>" +
"<etsiunitinfo>" +
"<etsideviceid>408</etsideviceid>" +
"<unittype>515</unittype>" +
"<interfaces>32513,256</interfaces>" +
"</etsiunitinfo>" +
"<alert>" +
"<state>0</state>" +
"</alert>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:HAN_FUN_CONTACT:1:119340059578_1"), discoveryResult.getThingUID());
assertEquals(HAN_FUN_CONTACT_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("119340059578-1", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("0x0feb", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("2002", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("119340059578-1", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("0.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validHANFUNMSmokeDetectorDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11324 0059952-1\" id=\"2003\" functionbitmask=\"8208\" fwversion=\"0.0\" manufacturer=\"0x2c3c\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #4: Unit #4</name>" +
"<etsiunitinfo>" +
"<etsideviceid>407</etsideviceid>" +
"<unittype>516</unittype>" +
"<interfaces>256</interfaces>" +
"</etsiunitinfo>" +
"<alert>" +
"<state>0</state>" +
"</alert>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:HAN_FUN_CONTACT:1:113240059952_1"), discoveryResult.getThingUID());
assertEquals(HAN_FUN_CONTACT_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("113240059952-1", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("0x2c3c", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("2003", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("113240059952-1", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("0.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validHANFUNSwitchtDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<device identifier=\"11934 0059578-1\" id=\"2001\" functionbitmask=\"8200\" fwversion=\"0.0\" manufacturer=\"0x0feb\" productname=\"HAN-FUN\">" +
"<present>1</present>" +
"<name>HAN-FUN #2: Unit #2</name>" +
"<etsiunitinfo>" +
"<etsideviceid>412</etsideviceid>" +
"<unittype>273</unittype>" +
"<interfaces>772</interfaces>" +
"</etsiunitinfo>" +
"<button>" +
"<lastpressedtimestamp>1529590797</lastpressedtimestamp>" +
"</button>" +
"</device>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:HAN_FUN_SWITCH:1:119340059578_1"), discoveryResult.getThingUID());
assertEquals(HAN_FUN_SWITCH_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("119340059578-1", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("0x0feb", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("2001", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("119340059578-1", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("0.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validHeatingGroupDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<group identifier=\"F0:A3:7F-900\" id=\"20000\" functionbitmask=\"4160\" fwversion=\"1.0\" manufacturer=\"AVM\" productname=\"\">" +
"<present>1</present>" +
"<name>Schlafzimmer</name>" +
"<hkr>" +
"<tist>0</tist>" +
"<tsoll>253</tsoll>" +
"<absenk>33</absenk>" +
"<komfort>40</komfort>" +
"<lock>1</lock>" +
"<devicelock>0</devicelock>" +
"<errorcode>0</errorcode>" +
"<batterylow>0</batterylow>" +
"<windowopenactiv>0</windowopenactiv>" +
"<battery>1</battery>" +
"<nextchange>" +
"<endperiod>1546293600</endperiod>" +
"<tchange>33</tchange>" +
"</nextchange>" +
"<summeractive>1</summeractive>" +
"<holidayactive>0</holidayactive>" +
"</hkr>" +
"<groupinfo>" +
"<masterdeviceid>1000</masterdeviceid>" +
"<members>20000</members>" +
"</groupinfo>" +
"</group>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_GROUP_HEATING:1:F0_A3_7F_900"), discoveryResult.getThingUID());
assertEquals(GROUP_HEATING_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("F0:A3:7F-900", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("20000", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("F0:A3:7F-900", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("1.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals("1000", discoveryResult.getProperties().get(PROPERTY_MASTER));
assertEquals("20000", discoveryResult.getProperties().get(PROPERTY_MEMBERS));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
@Test
public void validSwitchGroupDiscoveryResult() throws JAXBException {
//@formatter:off
String xml =
"<devicelist version=\"1\">" +
"<group identifier=\"F0:A3:7F-900\" id=\"20001\" functionbitmask=\"6784\" fwversion=\"1.0\" manufacturer=\"AVM\" productname=\"\">" +
"<present>1</present>" +
"<name>Schlafzimmer</name>" +
"<switch>" +
"<state>1</state>" +
"<mode>manuell</mode>" +
"<lock>0</lock>" +
"<devicelock>0</devicelock>" +
"</switch>" +
"<powermeter>" +
"<voltage>232850</voltage>" +
"<power>0</power>" +
"<energy>2087</energy>" +
"</powermeter>" +
"<groupinfo>" +
"<masterdeviceid>1000</masterdeviceid>" +
"<members>20000</members>" +
"</groupinfo>" +
"</group>" +
"</devicelist>";
//@formatter:on
Unmarshaller u = JAXBUtils.JAXBCONTEXT_DEVICES.createUnmarshaller();
DeviceListModel devices = (DeviceListModel) u.unmarshal(new StringReader(xml));
assertNotNull(devices);
assertEquals(1, devices.getDevicelist().size());
AVMFritzBaseModel device = devices.getDevicelist().get(0);
assertNotNull(device);
discovery.onDeviceAdded(device);
assertNotNull(discoveryResult);
assertEquals(DiscoveryResultFlag.NEW, discoveryResult.getFlag());
assertEquals(new ThingUID("avmfritz:FRITZ_GROUP_SWITCH:1:F0_A3_7F_900"), discoveryResult.getThingUID());
assertEquals(GROUP_SWITCH_THING_TYPE, discoveryResult.getThingTypeUID());
assertEquals(BRIGE_THING_ID, discoveryResult.getBridgeUID());
assertEquals("F0:A3:7F-900", discoveryResult.getProperties().get(CONFIG_AIN));
assertEquals("AVM", discoveryResult.getProperties().get(PROPERTY_VENDOR));
assertEquals("20001", discoveryResult.getProperties().get(PROPERTY_MODEL_ID));
assertEquals("F0:A3:7F-900", discoveryResult.getProperties().get(PROPERTY_SERIAL_NUMBER));
assertEquals("1.0", discoveryResult.getProperties().get(PROPERTY_FIRMWARE_VERSION));
assertEquals("1000", discoveryResult.getProperties().get(PROPERTY_MASTER));
assertEquals("20000", discoveryResult.getProperties().get(PROPERTY_MEMBERS));
assertEquals(CONFIG_AIN, discoveryResult.getRepresentationProperty());
}
}

View File

@@ -0,0 +1,111 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB 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.openhab.binding.avmfritz.internal.handler;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jetty.client.HttpClient;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ManagedThingProvider;
import org.openhab.core.thing.ThingProvider;
import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.binding.builder.BridgeBuilder;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.test.storage.VolatileStorageService;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openhab.binding.avmfritz.internal.AVMFritzDynamicCommandDescriptionProvider;
/**
* Tests for {@link AVMFritzThingHandlerOSGiTest}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@NonNullByDefault
public abstract class AVMFritzThingHandlerOSGiTest extends JavaOSGiTest {
private static HttpClient httpClient = new HttpClient();
private VolatileStorageService volatileStorageService = new VolatileStorageService();
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
protected @NonNullByDefault({}) Bridge bridge;
protected @NonNullByDefault({}) BoxHandler bridgeHandler;
@BeforeClass
public static void setUpClass() throws Exception {
httpClient.start();
}
@Before
public void setUp() {
registerService(volatileStorageService);
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertNotNull("Could not get ManagedThingProvider", managedThingProvider);
bridge = buildBridge();
assertNotNull(bridge.getConfiguration());
managedThingProvider.add(bridge);
ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
bridgeHandler = new BoxHandler(bridge, httpClient, mock(AVMFritzDynamicCommandDescriptionProvider.class));
assertNotNull(bridgeHandler);
bridgeHandler.setCallback(callback);
assertNull(bridge.getHandler());
bridge.setHandler(bridgeHandler);
assertNotNull(bridge.getHandler());
bridgeHandler.initialize();
}
@After
public void tearDown() {
if (bridge != null) {
managedThingProvider.remove(bridge.getUID());
}
unregisterService(volatileStorageService);
}
@AfterClass
public static void tearDownClass() throws Exception {
httpClient.stop();
}
private Bridge buildBridge() {
Map<String, Object> properties = new HashMap<>();
properties.put(CONFIG_IP_ADDRESS, "fritz.box");
properties.put(CONFIG_PROTOCOL, "http");
properties.put(CONFIG_USER, "user");
properties.put(CONFIG_PASSWORD, "password");
properties.put(CONFIG_POLLING_INTERVAL, 15);
properties.put(CONFIG_SYNC_TIMEOUT, 2000);
return BridgeBuilder.create(BRIDGE_THING_TYPE, "1").withLabel(BOX_MODEL_NAME)
.withConfiguration(new Configuration(properties)).build();
}
}