Skip to content

Commit

Permalink
[innogysmarthome] New version for innogy-API 1.1 (openhab#6389)
Browse files Browse the repository at this point in the history
Refactored to use openHAB OAuth2 and Http
Added BT-PSS (Bluetooth Pluggable Smart Switch)
Fix RST, Button-Issue and Channel-Trigger Event
General code improvements reported by SAT

Also-by: Oliver Kuhl <[email protected]> (github: ollie-dev)
Also-by: Nicholas Prinz <[email protected]>
Also-by: Ralph Sester <[email protected]>
Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand authored and Pshatsillo committed Dec 8, 2019
1 parent b5ad03a commit 9bd53c1
Show file tree
Hide file tree
Showing 108 changed files with 7,316 additions and 3,895 deletions.
11 changes: 11 additions & 0 deletions bundles/org.openhab.binding.innogysmarthome/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
134 changes: 70 additions & 64 deletions bundles/org.openhab.binding.innogysmarthome/README.md

Large diffs are not rendered by default.

Empty file.
42 changes: 2 additions & 40 deletions bundles/org.openhab.binding.innogysmarthome/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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>

Expand All @@ -13,43 +14,4 @@

<name>openHAB Add-ons :: Bundles :: innogy Smarthome Binding</name>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-osgi</artifactId>
<version>4.4.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<version>4.5.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openhab.osgiify</groupId>
<artifactId>com.google.http-client.google-http-client-gson</artifactId>
<version>1.27.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.27.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.27.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.innogysmarthome-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${project.version}/xml/features</repository>
<features name="org.openhab.binding.innogysmarthome-${project.version}"
xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${project.version}/xml/features</repository>

<feature name="openhab-binding-innogysmarthome" description="innogy Smarthome Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.apache.httpcomponents/httpcore-osgi/4.4.4</bundle>
<bundle dependency="true">mvn:org.apache.httpcomponents/httpclient-osgi/4.5.2</bundle>
<bundle dependency="true">mvn:com.google.guava/guava/20.0</bundle>
<bundle dependency="true">mvn:commons-codec/commons-codec/1.10</bundle>
<bundle dependency="true">mvn:com.google.oauth-client/google-oauth-client/1.27.0</bundle>
<bundle dependency="true">mvn:com.google.http-client/google-http-client/1.27.0</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/com.google.http-client.google-http-client-gson/1.27.0</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.innogysmarthome/${project.version}</bundle>
</feature>
<feature name="openhab-binding-innogysmarthome" description="innogy Smarthome Binding"
version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-transport-http</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.innogysmarthome/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,11 @@ public class InnogyBindingConstants {

// brands and client ids
public static final String BRAND_INNOGY_SMARTHOME = "innogy_smarthome";
public static final String BRAND_SMARTHOME_AUSTRIA = "smarthome_austria";
public static final String BRAND_START_SMARTHOME = "start_smarthome";
public static final String DEFAULT_BRAND = BRAND_INNOGY_SMARTHOME;

public static final String CLIENT_ID_INNOGY_SMARTHOME = "24635748";
public static final String CLIENT_ID_SMARTHOME_AUSTRIA = "24635749";
public static final String CLIENT_ID_START_SMARTHOME = "24635750";

public static final String CLIENT_SECRET_INNOGY_SMARTHOME = "no secret";
public static final String CLIENT_SECRET_SMARTHOME_AUSTRIA = "no secret";
public static final String CLIENT_SECRET_START_SMARTHOME = "no secret";

public static final String REDIRECT_URL_INNOGY_SMARTHOME = "https://www.openhab.org/oauth/innogy/innogy-smarthome.html";
public static final String REDIRECT_URL_SMARTHOME_AUSTRIA = "https://www.openhab.org/oauth/innogy/smarthome-austria.html";
public static final String REDIRECT_URL_START_SMARTHOME = "https://www.openhab.org/oauth/innogy/start-smarthome.html";

// Bridge config parameters
public static final String CONFIG_BRAND = "brand";
Expand All @@ -61,26 +51,40 @@ public class InnogyBindingConstants {
public static final long REINITIALIZE_DELAY_LONG_SECONDS = 120;

// API URLs
public static final String API_VERSION = "1.0";
public static final String API_VERSION = "1.1";
public static final String WEBSOCKET_API_URL_EVENTS = "wss://api.services-smarthome.de/API/" + API_VERSION
+ "/events?token={token}";

// properties
public static final String PROPERTY_ID = "id";
public static final String PROPERTY_VERSION = "Version";
public static final String PROPERTY_LOCATION = "Location";
public static final String PROPERTY_GEOLOCATION = "Geo Location";
public static final String PROPERTY_SOFTWARE_VERSION = "Software version";
public static final String PROPERTY_IP_ADDRESS = "IP address";
public static final String PROPERTY_REGISTRATION_TIME = "Registration Time";
public static final String PROPERTY_TIME_OF_ACCEPTANCE = "Time of acceptance";
public static final String PROPERTY_TIME_OF_DISCOVERY = "Time of discovery";
public static final String PROPERTY_BATTERY_POWERED = "Battery powered";
public static final String PROPERTY_DEVICE_TYPE = "Device Type";
public static final String PROPERTY_CONFIGURATION_STATE = "Configuration state";
public static final String PROPERTY_SHC_TYPE = "Controller Type";
public static final String PROPERTY_TIME_ZONE = "Time Zone";
public static final String PROPERTY_CURRENT_UTC_OFFSET = "Current UTC offset (minutes)";
public static final String PROPERTY_PROTOCOL_ID = "Protocol ID";
public static final String PROPERTY_BACKEND_CONNECTION_MONITORED = "Backend connection monitored";
public static final String PROPERTY_RFCOM_FAILURE_NOTIFICATION = "RFComm failure notification";
public static final String PROPERTY_DISPLAY_CURRENT_TEMPERATURE = "Display current temperature";
public static final String PROPERTY_UNDERLYING_DEVICE_IDS = "Underlying device IDs (thermostats)";
public static final String PROPERTY_METER_ID = "Meter ID";
public static final String PROPERTY_METER_FIRMWARE_VERSION = "Meter firmware version";

// List of main device types
public static final String DEVICE_SHC = "SHC"; // smarthome controller - the bridge
public static final String DEVICE_SHCA = "SHCA"; // smarthome controller version 2
public static final String DEVICE_PSS = "PSS"; // pluggable smart switch
public static final String DEVICE_PSSO = "PSSO"; // pluggable smart switch outdoor
public static final String DEVICE_BT_PSS = "BT-PSS"; // Bluetooth pluggable smart switch
public static final String DEVICE_VARIABLE_ACTUATOR = "VariableActuator";
public static final String DEVICE_RST = "RST"; // radiator mounted smart thermostat
public static final String DEVICE_RST2 = "RST2"; // radiator mounted smart thermostat (newer version)
Expand All @@ -102,18 +106,18 @@ public class InnogyBindingConstants {
public static final String DEVICE_SMART_METER = "SmartMeter";
public static final String DEVICE_TWO_WAY_METER = "TwoWayMeter";

public static final Set<String> SUPPORTED_DEVICES = Collections
.unmodifiableSet(Stream
.of(DEVICE_SHC, DEVICE_PSS, DEVICE_PSSO, DEVICE_VARIABLE_ACTUATOR, DEVICE_RST, DEVICE_RST2,
DEVICE_WRT, DEVICE_WDS, DEVICE_ISS2, DEVICE_WSD, DEVICE_WSD2, DEVICE_WMD, DEVICE_WMDO,
DEVICE_WSC2, DEVICE_BRC8, DEVICE_ISC2, DEVICE_ISD2, DEVICE_ISR2, DEVICE_PSD,
DEVICE_ANALOG_METER, DEVICE_GENERATION_METER, DEVICE_SMART_METER, DEVICE_TWO_WAY_METER)
.collect(Collectors.toSet()));
public static final Set<String> SUPPORTED_DEVICES = Collections.unmodifiableSet(Stream
.of(DEVICE_SHC, DEVICE_SHCA, DEVICE_PSS, DEVICE_PSSO, DEVICE_BT_PSS, DEVICE_VARIABLE_ACTUATOR, DEVICE_RST,
DEVICE_RST2, DEVICE_WRT, DEVICE_WDS, DEVICE_ISS2, DEVICE_WSD, DEVICE_WSD2, DEVICE_WMD, DEVICE_WMDO,
DEVICE_WSC2, DEVICE_BRC8, DEVICE_ISC2, DEVICE_ISD2, DEVICE_ISR2, DEVICE_PSD, DEVICE_ANALOG_METER,
DEVICE_GENERATION_METER, DEVICE_SMART_METER, DEVICE_TWO_WAY_METER)
.collect(Collectors.toSet()));

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final ThingTypeUID THING_TYPE_PSS = new ThingTypeUID(BINDING_ID, DEVICE_PSS);
public static final ThingTypeUID THING_TYPE_PSSO = new ThingTypeUID(BINDING_ID, DEVICE_PSSO);
public static final ThingTypeUID THING_TYPE_BT_PSS = new ThingTypeUID(BINDING_ID, DEVICE_BT_PSS);
public static final ThingTypeUID THING_TYPE_VARIABLE_ACTUATOR = new ThingTypeUID(BINDING_ID,
DEVICE_VARIABLE_ACTUATOR);
public static final ThingTypeUID THING_TYPE_RST = new ThingTypeUID(BINDING_ID, DEVICE_RST);
Expand All @@ -137,14 +141,12 @@ public class InnogyBindingConstants {
public static final ThingTypeUID THING_TYPE_SMART_METER = new ThingTypeUID(BINDING_ID, DEVICE_SMART_METER);
public static final ThingTypeUID THING_TYPE_TWO_WAY_METER = new ThingTypeUID(BINDING_ID, DEVICE_TWO_WAY_METER);

public static final Set<ThingTypeUID> SUPPORTED_DEVICE_THING_TYPES = Collections
.unmodifiableSet(Stream
.of(THING_TYPE_PSS, THING_TYPE_PSSO, THING_TYPE_VARIABLE_ACTUATOR, THING_TYPE_RST, THING_TYPE_RST2,
THING_TYPE_WRT, THING_TYPE_WDS, THING_TYPE_ISS2, THING_TYPE_WSD, THING_TYPE_WSD2,
THING_TYPE_WMD, THING_TYPE_WMDO, THING_TYPE_WSC2, THING_TYPE_BRC8, THING_TYPE_ISC2,
THING_TYPE_ISD2, THING_TYPE_ISR2, THING_TYPE_PSD, THING_TYPE_ANALOG_METER,
THING_TYPE_GENERATION_METER, THING_TYPE_SMART_METER, THING_TYPE_TWO_WAY_METER)
.collect(Collectors.toSet()));
public static final Set<ThingTypeUID> SUPPORTED_DEVICE_THING_TYPES = Collections.unmodifiableSet(
Stream.of(THING_TYPE_PSS, THING_TYPE_PSSO, THING_TYPE_BT_PSS, THING_TYPE_VARIABLE_ACTUATOR, THING_TYPE_RST,
THING_TYPE_RST2, THING_TYPE_WRT, THING_TYPE_WDS, THING_TYPE_ISS2, THING_TYPE_WSD, THING_TYPE_WSD2,
THING_TYPE_WMD, THING_TYPE_WMDO, THING_TYPE_WSC2, THING_TYPE_BRC8, THING_TYPE_ISC2, THING_TYPE_ISD2,
THING_TYPE_ISR2, THING_TYPE_PSD, THING_TYPE_ANALOG_METER, THING_TYPE_GENERATION_METER,
THING_TYPE_SMART_METER, THING_TYPE_TWO_WAY_METER).collect(Collectors.toSet()));

// List of all Channel ids
public static final String CHANNEL_SWITCH = "switch";
Expand All @@ -160,22 +162,8 @@ public class InnogyBindingConstants {
public static final String CHANNEL_FROST_WARNING = "frost_warning";
public static final String CHANNEL_MOLD_WARNING = "mold_warning";
public static final String CHANNEL_WINDOW_REDUCTION_ACTIVE = "window_reduction_active";
public static final String CHANNEL_BUTTON1 = "button1";
public static final String CHANNEL_BUTTON2 = "button2";
public static final String CHANNEL_BUTTON3 = "button3";
public static final String CHANNEL_BUTTON4 = "button4";
public static final String CHANNEL_BUTTON5 = "button5";
public static final String CHANNEL_BUTTON6 = "button6";
public static final String CHANNEL_BUTTON7 = "button7";
public static final String CHANNEL_BUTTON8 = "button8";
public static final String CHANNEL_BUTTON1_COUNT = "button1_count";
public static final String CHANNEL_BUTTON2_COUNT = "button2_count";
public static final String CHANNEL_BUTTON3_COUNT = "button3_count";
public static final String CHANNEL_BUTTON4_COUNT = "button4_count";
public static final String CHANNEL_BUTTON5_COUNT = "button5_count";
public static final String CHANNEL_BUTTON6_COUNT = "button6_count";
public static final String CHANNEL_BUTTON7_COUNT = "button7_count";
public static final String CHANNEL_BUTTON8_COUNT = "button8_count";
public static final String CHANNEL_BUTTON = "button";
public static final String CHANNEL_BUTTON_COUNT = "button%d_count";
public static final String CHANNEL_DIMMER = "dimmer";
public static final String CHANNEL_ROLLERSHUTTER = "rollershutter";
public static final String CHANNEL_BATTERY_LOW = "battery_low";
Expand All @@ -202,5 +190,7 @@ public class InnogyBindingConstants {
public static final String CHANNEL_ENERGY_FEED_DAY_EURO = "energy_feed_day_euro";
public static final String CHANNEL_ENERGY_FEED_DAY_KWH = "energy_feed_day_kwh";
public static final String CHANNEL_POWER_WATT = "power_watt";

public static final String CHANNEL_CPU = "cpu";
public static final String CHANNEL_DISK = "disk";
public static final String CHANNEL_MEMORY = "memory";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@
*/
package org.openhab.binding.innogysmarthome.internal;

import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.smarthome.core.auth.client.oauth2.OAuthFactory;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.openhab.binding.innogysmarthome.internal.discovery.InnogyDeviceDiscoveryService;
import org.eclipse.smarthome.io.net.http.HttpClientFactory;
import org.openhab.binding.innogysmarthome.internal.handler.InnogyBridgeHandler;
import org.openhab.binding.innogysmarthome.internal.handler.InnogyDeviceHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,61 +40,42 @@
* handlers.
*
* @author Oliver Kuhl - Initial contribution
* @author Hilbrand Bouwkamp - Refactored to use openHAB http and oauth2 libraries
*/
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.innogysmarthome")
@NonNullByDefault
public class InnogyHandlerFactory extends BaseThingHandlerFactory implements ThingHandlerFactory {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
.unmodifiableSet(Stream.concat(InnogyBridgeHandler.SUPPORTED_THING_TYPES.stream(),
InnogyDeviceHandler.SUPPORTED_THING_TYPES.stream()).collect(Collectors.toSet()));
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Stream
.concat(InnogyBridgeHandler.SUPPORTED_THING_TYPES.stream(),
InnogyDeviceHandler.SUPPORTED_THING_TYPES.stream())
.collect(Collectors.toSet());

private final Logger logger = LoggerFactory.getLogger(InnogyHandlerFactory.class);
private final Map<ThingUID, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();

private final OAuthFactory oAuthFactory;
private final HttpClient httpClient;

@Activate
public InnogyHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference HttpClientFactory httpClientFactory) {
this.oAuthFactory = oAuthFactory;
httpClient = httpClientFactory.getCommonHttpClient();
}

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES.contains(thingTypeUID);
}

@Override
protected ThingHandler createHandler(Thing thing) {
protected @Nullable ThingHandler createHandler(Thing thing) {
if (InnogyBridgeHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
InnogyBridgeHandler handler = new InnogyBridgeHandler((Bridge) thing);
registerDeviceDiscoveryService(handler);
return handler;
return new InnogyBridgeHandler((Bridge) thing, oAuthFactory, httpClient);
} else if (InnogyDeviceHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
InnogyDeviceHandler handler = new InnogyDeviceHandler(thing);
return handler;
return new InnogyDeviceHandler(thing);
} else {
logger.debug("Unsupported thing {}.", thing.getThingTypeUID());
return null;
}
}

/**
* Registers the device discovery service.
*
* @param bridgeHandler
*/
private synchronized void registerDeviceDiscoveryService(InnogyBridgeHandler bridgeHandler) {
InnogyDeviceDiscoveryService discoveryService = new InnogyDeviceDiscoveryService(bridgeHandler);
this.discoveryServiceRegs.put(bridgeHandler.getThing().getUID(),
bundleContext.registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>()));
}

@Override
protected synchronized void removeHandler(ThingHandler thingHandler) {
if (thingHandler instanceof InnogyBridgeHandler) {
ServiceRegistration<?> serviceReg = this.discoveryServiceRegs.remove(thingHandler.getThing().getUID());
if (serviceReg != null) {
// remove discovery service, if bridge handler is removed
InnogyDeviceDiscoveryService service = (InnogyDeviceDiscoveryService) bundleContext
.getService(serviceReg.getReference());
serviceReg.unregister();
if (service != null) {
service.deactivate();
}
}
}
}
}
Loading

0 comments on commit 9bd53c1

Please sign in to comment.