From 07abbafadc412512db3fbf0bf6db779ecea8c809 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sun, 15 Nov 2020 10:59:38 +0100 Subject: [PATCH] [remoteopenhab] Introduce things for the remote things and add support for HTTPS (#8909) * [remoteopenhab] Introduce things for the remote things Signed-off-by: Laurent Garnier * Adapt code to change in core Signed-off-by: Laurent Garnier * Review comment: scheduler.execute Signed-off-by: Laurent Garnier * Fixed tables in README Signed-off-by: Laurent Garnier * Review comment: ThingHandlerService Signed-off-by: Laurent Garnier * Add support for HTTPS communication Signed-off-by: Laurent Garnier * Few changes to satisfy build Signed-off-by: Laurent Garnier * Avoid SSE timeout exception after one minute when no event received Fix #8977 Signed-off-by: Laurent Garnier * Check connection job: do nothing when the thing was ONLINE and the REST API is still reachable Signed-off-by: Laurent Garnier * Review comment: super.deactivate Signed-off-by: Laurent Garnier * Review comments: README Signed-off-by: Laurent Garnier * Review comment: buildChannels parameter renamed Signed-off-by: Laurent Garnier * Imrpoved logging when the REST API is failing Signed-off-by: Laurent Garnier * Review comment: fasle Signed-off-by: Laurent Garnier * Review comment: deprecated "required" tag for channel parameter Signed-off-by: Laurent Garnier --- .../README.md | 72 +++- .../RemoteopenhabBindingConstants.java | 10 +- .../internal/RemoteopenhabHandlerFactory.java | 138 ++++++- ... => RemoteopenhabServerConfiguration.java} | 6 +- .../RemoteopenhabThingConfiguration.java | 30 ++ ...oteopenhabTriggerChannelConfiguration.java | 28 ++ .../internal/data/RemoteopenhabChannel.java | 29 ++ .../RemoteopenhabChannelTriggerEvent.java | 28 ++ .../{Event.java => RemoteopenhabEvent.java} | 2 +- ...ad.java => RemoteopenhabEventPayload.java} | 2 +- .../{Item.java => RemoteopenhabItem.java} | 4 +- ...RestApi.java => RemoteopenhabRestApi.java} | 6 +- ...java => RemoteopenhabRestApiEndpoint.java} | 2 +- ...nfo.java => RemoteopenhabRuntimeInfo.java} | 2 +- ...ava => RemoteopenhabStateDescription.java} | 6 +- ...ion.java => RemoteopenhabStateOption.java} | 4 +- .../data/RemoteopenhabStatusInfo.java | 29 ++ .../internal/data/RemoteopenhabThing.java | 37 ++ .../RemoteopenhabDiscoveryParticipant.java | 6 +- .../RemoteopenhabDiscoveryService.java | 148 ++++++++ .../handler/RemoteopenhabBridgeHandler.java | 142 ++++---- .../handler/RemoteopenhabThingHandler.java | 234 ++++++++++++ .../RemoteopenhabItemsDataListener.java | 46 +++ .../RemoteopenhabStreamingDataListener.java | 23 +- .../RemoteopenhabThingsDataListener.java | 48 +++ .../rest/RemoteopenhabRestClient.java | 340 +++++++++++++----- .../resources/OH-INF/thing/thing-types.xml | 59 ++- 27 files changed, 1249 insertions(+), 232 deletions(-) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/{RemoteopenhabInstanceConfiguration.java => RemoteopenhabServerConfiguration.java} (81%) create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabThingConfiguration.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabTriggerChannelConfiguration.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannel.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannelTriggerEvent.java rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{Event.java => RemoteopenhabEvent.java} (95%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{EventPayload.java => RemoteopenhabEventPayload.java} (94%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{Item.java => RemoteopenhabItem.java} (89%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{RestApi.java => RemoteopenhabRestApi.java} (80%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{RestApiEndpoint.java => RemoteopenhabRestApiEndpoint.java} (93%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{RuntimeInfo.java => RemoteopenhabRuntimeInfo.java} (94%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{StateDescription.java => RemoteopenhabStateDescription.java} (79%) rename bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/{Option.java => RemoteopenhabStateOption.java} (84%) create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabStatusInfo.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabThing.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/discovery/RemoteopenhabDiscoveryService.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabThingHandler.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/listener/RemoteopenhabItemsDataListener.java create mode 100644 bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/listener/RemoteopenhabThingsDataListener.java diff --git a/bundles/org.openhab.binding.remoteopenhab/README.md b/bundles/org.openhab.binding.remoteopenhab/README.md index 0947b3f9c..977f2daf0 100644 --- a/bundles/org.openhab.binding.remoteopenhab/README.md +++ b/bundles/org.openhab.binding.remoteopenhab/README.md @@ -3,11 +3,13 @@ The Remote openHAB binding allows to communicate with remote openHAB servers. The communication is bidirectional. The binding on the local server listens to any item state updates on the remote server and updates accordingly the linked channel on the local server. -It also transfers any item command from the local server to the remote server. +It transfers any item command from the local server to the remote server. +It can map any remote thing to a local thing. +Through this mapping, in your rules (local server), you can take actions based upon status updates or status changes generated by remote things and you can take actions based upon trigger events generated by the trigger channels defined in the remote thing. -One first usage is the distribution of your home automation system on a set of openHAB servers. +One use of this binding is to distribute your home automation system on multiple openHAB servers. -A second usage is for users having old openHAB v1 bindings running that were not migrated to openHAB v2 or openHAB v3. +Another use is for users to interact with older versions of openHAB that may support old openHAB v1 bindings that were not migrated to openHAB v2 or openHAB v3. They can keep an openHAB v2 server to run their old openHAB v1 bindings and setup a new openHAB v3 server for everything else. The Remote openHAB binding installed on the openHAB v3 server will then allow to use the openHAB v1 bindings through communication with the openHAB v2 server. @@ -15,7 +17,7 @@ A third usage is for users that would like to keep unchanged an existing openHAB ## Supported Things -There is one unique supported thing : the `server` bridge thing +There is two supported things : the `server` bridge thing representing a remote openHAB server and the `thing` thing representing a thing from the remote openHAB server. ## Discovery @@ -24,39 +26,75 @@ You will find in the inbox one discovery thing per remote server interface. So if your remote server has one IPv4 address and one IPv6 address, you will discover two things in the inbox. Just choose one of the two things. +Once a bridge thing representing a remote openHAB server is created, all things from this remote server will be discovered when you scan for new things. + ## Binding Configuration The binding has no configuration options, all configuration is done at Thing level. ## Thing Configuration -The thing has the following configuration parameters: +The `server` thing has the following configuration parameters: -| Parameter | Required | Description | -|-----------|-------------------------------------------------------------------------------------------------------------------| -| host | yes | The host name or IP address of the remote openHAB server. | -| port | yes | The HTTP port to be used to communicate with the remote openHAB server. Default is 8080. | -| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest | -| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. | +| Parameter | Required | Description | +|--------------------|----------|-----------------------------------------------------------------------------------------------------------| +| host | yes | The host name or IP address of the remote openHAB server. | +| useHttps | no | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false. | +| port | yes | The HTTP port to use to communicate with the remote openHAB server. Default is 8080. | +| trustedCertificate | no | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. | +| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest | +| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. | + +The `thing` thing has the following configuration parameters: + +| Parameter | Required | Description | +|----------------------|----------|---------------------------------------------| +| thingUID | yes | The thing UID in the remote openHAB server. | +| buildTriggerChannels | no | If set to true, a trigger channel will be automatically created and linked to each trigger channel from the remote thing. Default is true. | + +Please note that if your remote server is an openHAB v3 server, you will need to define a valid token on your bridge thing to have your things correctly initialized. + +Setting the `buildTriggerChannels` parameter to false is for the main following advanced usages : + +* you don't care about the trigger channels of this remote thing and you don't want the binding to create them locally, +* you want to define the trigger channels in your configuration file, and only the channels that you will finally need, +* you want to set a specific channel ID rather than using the channel ID created by the binding. + +## Thing Status + +The status of any `thing` thing is a mapping of the remote thing status. +A mapping is done only when the `server` bridge is ONLINE (meaning the local server is connected to the remote server). +Please note that every remote status other than UNKNOWN, ONLINE and OFFLINE will then be considered as OFFLINE on the local server. ## Channels -The channels are built dynamically and automatically by the binding. -One channel is created for each item from the remote server. -Only basic groups (with no state) are ignored. -The channel id of the built channel corresponds to the name of the item on the remote server. +Channels are built dynamically and automatically by the binding. + +On the `server` thing, a channel is created automatically for each item defined in the remote server. +Only basic groups (with no state) from the remote server are ignored. +The channel ID of the created channel corresponds to the name of the item on the remote server. +For example, if your remote item is named `MyDate`, the channel UID of the channel created by the binding will be `remoteopenhab:server:xxx:MyDate`. + +On the `thing` thing, if the `buildTriggerChannels` parameter is set to true, a channel is created automatically for each trigger channel defined in the remote thing. +For example, if your remote thing provides a trigger channel with this UID `astro:sun:local:night#event`, the channel UID of the channel created by the binding will be `remoteopenhab:thing:xxx:astro_sun_local_night_event`. ## Limitations * The binding will not try to communicate with an openHAB v1 server. -* The binding only uses the HTTP protocol for the communications with the remote server (not HTTPS). ## Example ### demo.things: ``` -Bridge remoteopenhab:server:oh2 "OH2 server" [ host="192.168.0.100" ] +Bridge remoteopenhab:server:oh2 "OH2 server" [ host="192.168.0.100", port=8443, useHttps=true, trustedCertificate=true ] { + Thing thing tv "TV living room" [ thingUID="lgwebos:WebOSTV:tv" ] + Thing thing astroSun "Astro sun" [ thingUID="astro:sun:local", buildTriggerChannels=false ] { + Channels: + Type trigger : nightEvent "Night Event" [ channelUID="astro:sun:local:night#event" ] + } + Thing thing astroMoon "Astro moon" [ thingUID="astro:moon:local" ] +} ``` ### demo.items: diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabBindingConstants.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabBindingConstants.java index 20407c7a6..57e7d10dc 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabBindingConstants.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabBindingConstants.java @@ -31,6 +31,14 @@ public class RemoteopenhabBindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID BRIDGE_TYPE_SERVER = new ThingTypeUID(BINDING_ID, "server"); + public static final ThingTypeUID THING_TYPE_THING = new ThingTypeUID(BINDING_ID, "thing"); - public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(BRIDGE_TYPE_SERVER); + // All supported Bridge types + public static final Set SUPPORTED_BRIDGE_TYPES_UIDS = Collections.singleton(BRIDGE_TYPE_SERVER); + + // All supported Thing types + public static final Set SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_THING); + + // List of all channel types + public static final String CHANNEL_TYPE_TRIGGER = "trigger"; } diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabHandlerFactory.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabHandlerFactory.java index cd57ccab1..edfad0db2 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabHandlerFactory.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/RemoteopenhabHandlerFactory.java @@ -12,23 +12,42 @@ */ package org.openhab.binding.remoteopenhab.internal; -import static org.openhab.binding.remoteopenhab.internal.RemoteopenhabBindingConstants.*; +import java.net.Socket; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509ExtendedTrustManager; import javax.ws.rs.client.ClientBuilder; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.remoteopenhab.internal.handler.RemoteopenhabBridgeHandler; +import org.openhab.binding.remoteopenhab.internal.handler.RemoteopenhabThingHandler; +import org.openhab.core.config.core.Configuration; +import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.ThingUID; import org.openhab.core.thing.binding.BaseThingHandlerFactory; import org.openhab.core.thing.binding.ThingHandler; import org.openhab.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.jaxrs.client.SseEventSourceFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; @@ -44,22 +63,103 @@ import com.google.gson.GsonBuilder; @Component(service = ThingHandlerFactory.class, configurationPid = "binding.remoteopenhab") public class RemoteopenhabHandlerFactory extends BaseThingHandlerFactory { + private static final Set SUPPORTED_THING_TYPES_UIDS = Stream + .concat(RemoteopenhabBindingConstants.SUPPORTED_BRIDGE_TYPES_UIDS.stream(), + RemoteopenhabBindingConstants.SUPPORTED_THING_TYPES_UIDS.stream()) + .collect(Collectors.toSet()); + + private final Logger logger = LoggerFactory.getLogger(RemoteopenhabHandlerFactory.class); + + private final HttpClient httpClient; private final ClientBuilder clientBuilder; private final SseEventSourceFactory eventSourceFactory; private final RemoteopenhabChannelTypeProvider channelTypeProvider; private final RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider; private final Gson jsonParser; + private HttpClient httpClientTrustingCert; + @Activate - public RemoteopenhabHandlerFactory(final @Reference ClientBuilder clientBuilder, - final @Reference SseEventSourceFactory eventSourceFactory, + public RemoteopenhabHandlerFactory(final @Reference HttpClientFactory httpClientFactory, + final @Reference ClientBuilder clientBuilder, final @Reference SseEventSourceFactory eventSourceFactory, final @Reference RemoteopenhabChannelTypeProvider channelTypeProvider, final @Reference RemoteopenhabStateDescriptionOptionProvider stateDescriptionProvider) { + this.httpClient = httpClientFactory.getCommonHttpClient(); + this.httpClientTrustingCert = httpClientFactory.createHttpClient(RemoteopenhabBindingConstants.BINDING_ID); this.clientBuilder = clientBuilder; this.eventSourceFactory = eventSourceFactory; this.channelTypeProvider = channelTypeProvider; this.stateDescriptionProvider = stateDescriptionProvider; - jsonParser = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create(); + this.jsonParser = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).create(); + + try { + SSLContext sslContext = SSLContext.getInstance("SSL"); + + TrustManager[] trustAllCerts = new TrustManager[] { new X509ExtendedTrustManager() { + @Override + public void checkClientTrusted(X509Certificate @Nullable [] chain, @Nullable String authType) + throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate @Nullable [] chain, @Nullable String authType) + throws CertificateException { + } + + @Override + public X509Certificate @Nullable [] getAcceptedIssuers() { + return null; + } + + @Override + public void checkClientTrusted(X509Certificate @Nullable [] chain, @Nullable String authType, + @Nullable Socket socket) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate @Nullable [] chain, @Nullable String authType, + @Nullable Socket socket) throws CertificateException { + } + + @Override + public void checkClientTrusted(X509Certificate @Nullable [] chain, @Nullable String authType, + @Nullable SSLEngine engine) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate @Nullable [] chain, @Nullable String authType, + @Nullable SSLEngine engine) throws CertificateException { + } + } }; + sslContext.init(null, trustAllCerts, null); + + this.httpClientTrustingCert.getSslContextFactory().setSslContext(sslContext); + } catch (NoSuchAlgorithmException e) { + logger.warn("An exception occurred while requesting the SSL encryption algorithm : '{}'", e.getMessage(), + e); + } catch (KeyManagementException e) { + logger.warn("An exception occurred while initialising the SSL context : '{}'", e.getMessage(), e); + } + } + + @Override + protected void activate(ComponentContext componentContext) { + super.activate(componentContext); + try { + httpClientTrustingCert.start(); + } catch (Exception e) { + logger.warn("Unable to start Jetty HttpClient", e); + } + } + + @Override + protected void deactivate(ComponentContext componentContext) { + try { + httpClientTrustingCert.stop(); + } catch (Exception e) { + logger.warn("Unable to stop Jetty HttpClient", e); + } + super.deactivate(componentContext); } /** @@ -70,16 +170,36 @@ public class RemoteopenhabHandlerFactory extends BaseThingHandlerFactory { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } + @Override + public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, + @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) { + if (thingTypeUID.equals(RemoteopenhabBindingConstants.BRIDGE_TYPE_SERVER)) { + return super.createThing(thingTypeUID, configuration, thingUID, null); + } else if (RemoteopenhabBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { + ThingUID newThingUID; + if (bridgeUID != null && thingUID != null) { + newThingUID = new ThingUID(thingTypeUID, bridgeUID, thingUID.getId()); + } else { + newThingUID = thingUID; + } + return super.createThing(thingTypeUID, configuration, newThingUID, bridgeUID); + } + throw new IllegalArgumentException( + "The thing type " + thingTypeUID + " is not supported by the remote openHAB binding."); + } + /** * Creates a handler for the specific thing. */ @Override protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); - - return BRIDGE_TYPE_SERVER.equals(thingTypeUID) - ? new RemoteopenhabBridgeHandler((Bridge) thing, clientBuilder, eventSourceFactory, channelTypeProvider, - stateDescriptionProvider, jsonParser) - : null; + if (thingTypeUID.equals(RemoteopenhabBindingConstants.BRIDGE_TYPE_SERVER)) { + return new RemoteopenhabBridgeHandler((Bridge) thing, httpClient, httpClientTrustingCert, clientBuilder, + eventSourceFactory, channelTypeProvider, stateDescriptionProvider, jsonParser); + } else if (RemoteopenhabBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { + return new RemoteopenhabThingHandler(thing); + } + return null; } } diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabInstanceConfiguration.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java similarity index 81% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabInstanceConfiguration.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java index 4b2093060..cbb0c8242 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabInstanceConfiguration.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java @@ -15,20 +15,22 @@ package org.openhab.binding.remoteopenhab.internal.config; import org.eclipse.jdt.annotation.NonNullByDefault; /** - * The {@link RemoteopenhabInstanceConfiguration} is responsible for holding + * The {@link RemoteopenhabServerConfiguration} is responsible for holding * configuration informations associated to a remote openHAB server * thing type * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class RemoteopenhabInstanceConfiguration { +public class RemoteopenhabServerConfiguration { public static final String HOST = "host"; public static final String PORT = "port"; public static final String REST_PATH = "restPath"; public String host = ""; + public boolean useHttps = false; public int port = 8080; + public boolean trustedCertificate = false; public String restPath = "/rest"; public String token = ""; } diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabThingConfiguration.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabThingConfiguration.java new file mode 100644 index 000000000..b03e7a377 --- /dev/null +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabThingConfiguration.java @@ -0,0 +1,30 @@ +/** + * 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.remoteopenhab.internal.config; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link RemoteopenhabThingConfiguration} is responsible for holding + * configuration informations associated to a remote openHAB thing + * thing type + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public class RemoteopenhabThingConfiguration { + public static final String THING_UID = "thingUID"; + + public String thingUID = ""; + public boolean buildTriggerChannels = true; +} diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabTriggerChannelConfiguration.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabTriggerChannelConfiguration.java new file mode 100644 index 000000000..5edd119bb --- /dev/null +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabTriggerChannelConfiguration.java @@ -0,0 +1,28 @@ +/** + * 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.remoteopenhab.internal.config; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link RemoteopenhabTriggerChannelConfiguration} is responsible for holding + * configuration informations associated to a remote openHAB trigger channel + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public class RemoteopenhabTriggerChannelConfiguration { + public static final String CHANNEL_UID = "channelUID"; + + public String channelUID = ""; +} diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannel.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannel.java new file mode 100644 index 000000000..3c3b42f97 --- /dev/null +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannel.java @@ -0,0 +1,29 @@ +/** + * 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.remoteopenhab.internal.data; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * Part of {@link RemoteopenhabThing} containing the channel definition + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public class RemoteopenhabChannel { + + public String uid = ""; + public String kind = ""; + public String label = ""; + public String description = ""; +} diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannelTriggerEvent.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannelTriggerEvent.java new file mode 100644 index 000000000..b28f4e4d8 --- /dev/null +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabChannelTriggerEvent.java @@ -0,0 +1,28 @@ +/** + * 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.remoteopenhab.internal.data; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * Payload from ChannelTriggerEvent events received through the SSE connection. + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public class RemoteopenhabChannelTriggerEvent { + + public String channel = ""; + public @Nullable String event; +} diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Event.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEvent.java similarity index 95% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Event.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEvent.java index e37cbf411..97f69d54e 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Event.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEvent.java @@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class Event { +public class RemoteopenhabEvent { public String type = ""; public String topic = ""; diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/EventPayload.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEventPayload.java similarity index 94% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/EventPayload.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEventPayload.java index 2fceb9d19..84327fd14 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/EventPayload.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabEventPayload.java @@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class EventPayload { +public class RemoteopenhabEventPayload { public String type = ""; public String value = ""; diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Item.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabItem.java similarity index 89% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Item.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabItem.java index 6c0cab673..ee10be07f 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/Item.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabItem.java @@ -22,11 +22,11 @@ import org.eclipse.jdt.annotation.Nullable; * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class Item { +public class RemoteopenhabItem { public String name = ""; public String type = ""; public String state = ""; public String groupType = ""; - public @Nullable StateDescription stateDescription; + public @Nullable RemoteopenhabStateDescription stateDescription; } diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApi.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApi.java similarity index 80% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApi.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApi.java index 0ac3e1c80..e76837455 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApi.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApi.java @@ -19,9 +19,9 @@ import org.eclipse.jdt.annotation.Nullable; * * @author Laurent Garnier - Initial contribution */ -public class RestApi { +public class RemoteopenhabRestApi { public String version; - public RestApiEndpoint[] links; - public @Nullable RuntimeInfo runtimeInfo; + public RemoteopenhabRestApiEndpoint[] links; + public @Nullable RemoteopenhabRuntimeInfo runtimeInfo; } diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApiEndpoint.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApiEndpoint.java similarity index 93% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApiEndpoint.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApiEndpoint.java index eda714e32..c17cd4811 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RestApiEndpoint.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRestApiEndpoint.java @@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class RestApiEndpoint { +public class RemoteopenhabRestApiEndpoint { public String type = ""; public String url = ""; diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RuntimeInfo.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRuntimeInfo.java similarity index 94% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RuntimeInfo.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRuntimeInfo.java index e17675d0a..cbf38e9cf 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RuntimeInfo.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabRuntimeInfo.java @@ -20,7 +20,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class RuntimeInfo { +public class RemoteopenhabRuntimeInfo { public String version = ""; public String buildString = ""; diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/StateDescription.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabStateDescription.java similarity index 79% rename from bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/StateDescription.java rename to bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabStateDescription.java index b2b7a4860..c82f74580 100644 --- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/StateDescription.java +++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/data/RemoteopenhabStateDescription.java @@ -18,14 +18,14 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; /** - * Part of {@link Item} containing the state description + * Part of {@link RemoteopenhabItem} containing the state description * * @author Laurent Garnier - Initial contribution */ @NonNullByDefault -public class StateDescription { +public class RemoteopenhabStateDescription { public String pattern = ""; public boolean readOnly; - public @Nullable List