From 5ae65723151d1d84cd9a9edb80bf7992b767e896 Mon Sep 17 00:00:00 2001 From: Av3m <7688354+Av3m@users.noreply.github.com> Date: Fri, 7 Jan 2022 13:56:23 +0100 Subject: [PATCH] initial commit for ecowitt binding --- bom/openhab-addons/pom.xml | 4 + bundles/org.openhab.binding.ecowitt/NOTICE | 13 +++ bundles/org.openhab.binding.ecowitt/README.md | 56 ++++++++++ bundles/org.openhab.binding.ecowitt/pom.xml | 17 +++ .../src/main/feature/feature.xml | 9 ++ .../internal/ecowittBindingConstants.java | 34 ++++++ .../internal/ecowittConfiguration.java | 28 +++++ .../ecowitt/internal/ecowittHandler.java | 100 ++++++++++++++++++ .../internal/ecowittHandlerFactory.java | 55 ++++++++++ .../main/resources/OH-INF/binding/binding.xml | 9 ++ .../OH-INF/i18n/ecowitt_xx.properties | 21 ++++ .../resources/OH-INF/thing/thing-types.xml | 46 ++++++++ bundles/pom.xml | 1 + 13 files changed, 393 insertions(+) create mode 100644 bundles/org.openhab.binding.ecowitt/NOTICE create mode 100644 bundles/org.openhab.binding.ecowitt/README.md create mode 100644 bundles/org.openhab.binding.ecowitt/pom.xml create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/feature/feature.xml create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittBindingConstants.java create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittConfiguration.java create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandler.java create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandlerFactory.java create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/binding/binding.xml create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/i18n/ecowitt_xx.properties create mode 100644 bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/thing/thing-types.xml diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index f31356f0c..6a75a19b6 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -431,12 +431,16 @@ org.openhab.addons.bundles +<<<<<<< HEAD org.openhab.binding.ecovacs ${project.version} org.openhab.addons.bundles org.openhab.binding.ecowatt +======= + org.openhab.binding.ecowitt +>>>>>>> 833ca96673 (initial commit for ecowitt binding) ${project.version} diff --git a/bundles/org.openhab.binding.ecowitt/NOTICE b/bundles/org.openhab.binding.ecowitt/NOTICE new file mode 100644 index 000000000..38d625e34 --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/NOTICE @@ -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 diff --git a/bundles/org.openhab.binding.ecowitt/README.md b/bundles/org.openhab.binding.ecowitt/README.md new file mode 100644 index 000000000..cb1dadddb --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/README.md @@ -0,0 +1,56 @@ +# ecowitt Binding + +_Give some details about what this binding is meant for - a protocol, system, specific device._ + +_If possible, provide some resources like pictures, a video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._ + +## Supported Things + +_Please describe the different supported things / devices within this section._ +_Which different types are supported, which models were tested etc.?_ +_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._ + +## Discovery + +_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._ + +## Binding Configuration + +_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_ + +``` +# Configuration for the ecowitt Binding +# +# Default secret key for the pairing of the ecowitt Thing. +# It has to be between 10-40 (alphanumeric) characters. +# This may be changed by the user for security reasons. +secret=openHABSecret +``` + +_Note that it is planned to generate some part of this based on the information that is available within ```src/main/resources/OH-INF/binding``` of your binding._ + +_If your binding does not offer any generic configurations, you can remove this section completely._ + +## Thing Configuration + +_Describe what is needed to manually configure a thing, either through the UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_ + +_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._ + +## Channels + +_Here you should provide information about available channel types, what their meaning is and how they can be used._ + +_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._ + +| channel | type | description | +|----------|--------|------------------------------| +| control | Switch | This is the control channel | + +## Full Example + +_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._ + +## Any custom content here! + +_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_ diff --git a/bundles/org.openhab.binding.ecowitt/pom.xml b/bundles/org.openhab.binding.ecowitt/pom.xml new file mode 100644 index 000000000..be902241c --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + 3.2.0-SNAPSHOT + + + org.openhab.binding.ecowitt + + openHAB Add-ons :: Bundles :: ecowitt Binding + + diff --git a/bundles/org.openhab.binding.ecowitt/src/main/feature/feature.xml b/bundles/org.openhab.binding.ecowitt/src/main/feature/feature.xml new file mode 100644 index 000000000..6b7a37042 --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/feature/feature.xml @@ -0,0 +1,9 @@ + + + mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features + + + openhab-runtime-base + mvn:org.openhab.addons.bundles/org.openhab.binding.ecowitt/${project.version} + + diff --git a/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittBindingConstants.java b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittBindingConstants.java new file mode 100644 index 000000000..5355b38a6 --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittBindingConstants.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2022 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.ecowitt.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ThingTypeUID; + +/** + * The {@link ecowittBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +public class ecowittBindingConstants { + + private static final String BINDING_ID = "ecowitt"; + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "sample"); + + // List of all Channel ids + public static final String CHANNEL_1 = "channel1"; +} diff --git a/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittConfiguration.java b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittConfiguration.java new file mode 100644 index 000000000..4bc9ad48c --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittConfiguration.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2010-2022 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.ecowitt.internal; + +/** + * The {@link ecowittConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Av3m - Initial contribution + */ +public class ecowittConfiguration { + + /** + * Sample configuration parameters. Replace with your own. + */ + public String hostname; + public String password; + public int refreshInterval; +} diff --git a/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandler.java b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandler.java new file mode 100644 index 000000000..f62c82b1c --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandler.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2010-2022 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.ecowitt.internal; + +import static org.openhab.binding.ecowitt.internal.ecowittBindingConstants.*; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingStatus; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The {@link ecowittHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +public class ecowittHandler extends BaseThingHandler { + + private final Logger logger = LoggerFactory.getLogger(ecowittHandler.class); + + private @Nullable ecowittConfiguration config; + + public ecowittHandler(Thing thing) { + super(thing); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (CHANNEL_1.equals(channelUID.getId())) { + if (command instanceof RefreshType) { + // TODO: handle data refresh + } + + // TODO: handle command + + // Note: if communication with thing fails for some reason, + // indicate that by setting the status with detail information: + // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + // "Could not control device at IP address x.x.x.x"); + } + } + + @Override + public void initialize() { + config = getConfigAs(ecowittConfiguration.class); + + // TODO: Initialize the handler. + // The framework requires you to return from this method quickly. Also, before leaving this method a thing + // status from one of ONLINE, OFFLINE or UNKNOWN must be set. This might already be the real thing status in + // case you can decide it directly. + // In case you can not decide the thing status directly (e.g. for long running connection handshake using WAN + // access or similar) you should set status UNKNOWN here and then decide the real status asynchronously in the + // background. + + // set the thing status to UNKNOWN temporarily and let the background task decide for the real status. + // the framework is then able to reuse the resources from the thing handler initialization. + // we set this upfront to reliably check status updates in unit tests. + updateStatus(ThingStatus.UNKNOWN); + + // Example for background initialization: + scheduler.execute(() -> { + boolean thingReachable = true; // + // when done do: + if (thingReachable) { + updateStatus(ThingStatus.ONLINE); + } else { + updateStatus(ThingStatus.OFFLINE); + } + }); + + // These logging types should be primarily used by bindings + // logger.trace("Example trace message"); + // logger.debug("Example debug message"); + // logger.warn("Example warn message"); + + // Note: When initialization can NOT be done set the status with more details for further + // analysis. See also class ThingStatusDetail for all available status details. + // Add a description to give user information to understand why thing does not work as expected. E.g. + // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + // "Can not access device as username and/or password are invalid"); + } +} diff --git a/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandlerFactory.java b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandlerFactory.java new file mode 100644 index 000000000..fab3a4e0b --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/java/org/openhab/binding/ecowitt/internal/ecowittHandlerFactory.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2010-2022 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.ecowitt.internal; + +import static org.openhab.binding.ecowitt.internal.ecowittBindingConstants.*; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingTypeUID; +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.annotations.Component; + +/** + * The {@link ecowittHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +@Component(configurationPid = "binding.ecowitt", service = ThingHandlerFactory.class) +public class ecowittHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_SAMPLE); + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected @Nullable ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (THING_TYPE_SAMPLE.equals(thingTypeUID)) { + return new ecowittHandler(thing); + } + + return null; + } +} diff --git a/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/binding/binding.xml new file mode 100644 index 000000000..db5da1e0a --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/binding/binding.xml @@ -0,0 +1,9 @@ + + + + ecowitt Binding + This is the binding for ecowitt. + + diff --git a/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/i18n/ecowitt_xx.properties b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/i18n/ecowitt_xx.properties new file mode 100644 index 000000000..209b7a86d --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/i18n/ecowitt_xx.properties @@ -0,0 +1,21 @@ +# FIXME: please substitute the xx with a proper locale, ie. de +# FIXME: please do not add the file to the repo if you add or change no content +# binding +binding.ecowitt.name = +binding.ecowitt.description = + +# thing types +thing-type.ecowitt.sample.label = +thing-type.ecowitt.sample.description = + +# thing type config description +thing-type.config.ecowitt.sample.hostname.label = +thing-type.config.ecowitt.sample.hostname.description = +thing-type.config.ecowitt.sample.password.label = +thing-type.config.ecowitt.sample.password.description = +thing-type.config.ecowitt.sample.refreshInterval.label = +thing-type.config.ecowitt.sample.refreshInterval.description = + +# channel types +channel-type.ecowitt.sample-channel.label = +channel-type.ecowitt.sample-channel.description = diff --git a/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/thing/thing-types.xml new file mode 100644 index 000000000..04c8e3c1f --- /dev/null +++ b/bundles/org.openhab.binding.ecowitt/src/main/resources/OH-INF/thing/thing-types.xml @@ -0,0 +1,46 @@ + + + + + + + + + Sample thing for ecowitt Binding + + + + + + + + network-address + + Hostname or IP address of the device + + + password + + Passwort to access the device + + + + Interval the device is polled in sec. + + + + + + + Number:Temperature + + Sample channel for ecowitt Binding + + diff --git a/bundles/pom.xml b/bundles/pom.xml index bdfba62b8..6174aacff 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -120,6 +120,7 @@ org.openhab.binding.ecotouch org.openhab.binding.ecovacs org.openhab.binding.ecowatt + org.openhab.binding.ecowitt org.openhab.binding.ekey org.openhab.binding.electroluxair org.openhab.binding.elerotransmitterstick