diff --git a/CODEOWNERS b/CODEOWNERS index 59a56ddd9..286b704dc 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -197,6 +197,7 @@ /bundles/org.openhab.binding.mcp23017/ @aogorek /bundles/org.openhab.binding.meater/ @jannegpriv /bundles/org.openhab.binding.mecmeter/ @kaikreuzer +/bundles/org.openhab.binding.mediolaaiogateway/ @Av3m /bundles/org.openhab.binding.melcloud/ @lucacalcaterra @paulianttila @thewiep /bundles/org.openhab.binding.mercedesme/ @weymann /bundles/org.openhab.binding.meteoalerte/ @clinique diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index 00419970d..7ef33626f 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -976,6 +976,11 @@ org.openhab.binding.mecmeter ${project.version} + + org.openhab.addons.bundles + org.openhab.binding.mediolaaiogateway + ${project.version} + org.openhab.addons.bundles org.openhab.binding.melcloud diff --git a/bundles/org.openhab.binding.mediolaaiogateway/NOTICE b/bundles/org.openhab.binding.mediolaaiogateway/NOTICE new file mode 100644 index 000000000..38d625e34 --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/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.mediolaaiogateway/README.md b/bundles/org.openhab.binding.mediolaaiogateway/README.md new file mode 100644 index 000000000..9a06dc057 --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/README.md @@ -0,0 +1,56 @@ +# MediolaAioGateway 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 MediolaAioGateway Binding +# +# Default secret key for the pairing of the MediolaAioGateway 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.mediolaaiogateway/pom.xml b/bundles/org.openhab.binding.mediolaaiogateway/pom.xml new file mode 100644 index 000000000..da5e3167d --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/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.mediolaaiogateway + + openHAB Add-ons :: Bundles :: MediolaAioGateway Binding + + diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/feature/feature.xml b/bundles/org.openhab.binding.mediolaaiogateway/src/main/feature/feature.xml new file mode 100644 index 000000000..dfcb1840c --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/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.mediolaaiogateway/${project.version} + + diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayBindingConstants.java b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayBindingConstants.java new file mode 100644 index 000000000..ba0e2efbb --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayBindingConstants.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2010-2021 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.mediolaaiogateway.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ThingTypeUID; + +/** + * The {@link MediolaAioGatewayBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +public class MediolaAioGatewayBindingConstants { + + private static final String BINDING_ID = "mediolaaiogateway"; + + // 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.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayConfiguration.java b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayConfiguration.java new file mode 100644 index 000000000..7e1a65579 --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayConfiguration.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2010-2021 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.mediolaaiogateway.internal; + +/** + * The {@link MediolaAioGatewayConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Av3m - Initial contribution + */ +public class MediolaAioGatewayConfiguration { + + /** + * Sample configuration parameters. Replace with your own. + */ + public String hostname; + public String password; + public int refreshInterval; +} diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandler.java b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandler.java new file mode 100644 index 000000000..43acd7b5e --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandler.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2010-2021 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.mediolaaiogateway.internal; + +import static org.openhab.binding.mediolaaiogateway.internal.MediolaAioGatewayBindingConstants.*; + +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 MediolaAioGatewayHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +public class MediolaAioGatewayHandler extends BaseThingHandler { + + private final Logger logger = LoggerFactory.getLogger(MediolaAioGatewayHandler.class); + + private @Nullable MediolaAioGatewayConfiguration config; + + public MediolaAioGatewayHandler(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(MediolaAioGatewayConfiguration.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.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandlerFactory.java b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandlerFactory.java new file mode 100644 index 000000000..4110fdc90 --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/java/org/openhab/binding/mediolaaiogateway/internal/MediolaAioGatewayHandlerFactory.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2010-2021 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.mediolaaiogateway.internal; + +import static org.openhab.binding.mediolaaiogateway.internal.MediolaAioGatewayBindingConstants.*; + +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 MediolaAioGatewayHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Av3m - Initial contribution + */ +@NonNullByDefault +@Component(configurationPid = "binding.mediolaaiogateway", service = ThingHandlerFactory.class) +public class MediolaAioGatewayHandlerFactory 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 MediolaAioGatewayHandler(thing); + } + + return null; + } +} diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/binding/binding.xml new file mode 100644 index 000000000..71c1c8e6b --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/binding/binding.xml @@ -0,0 +1,9 @@ + + + + MediolaAioGateway Binding + This is the binding for MediolaAioGateway. + + diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/i18n/mediolaaiogateway_xx.properties b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/i18n/mediolaaiogateway_xx.properties new file mode 100644 index 000000000..c869f5edd --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/i18n/mediolaaiogateway_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.mediolaaiogateway.name = +binding.mediolaaiogateway.description = + +# thing types +thing-type.mediolaaiogateway.sample.label = +thing-type.mediolaaiogateway.sample.description = + +# thing type config description +thing-type.config.mediolaaiogateway.sample.hostname.label = +thing-type.config.mediolaaiogateway.sample.hostname.description = +thing-type.config.mediolaaiogateway.sample.password.label = +thing-type.config.mediolaaiogateway.sample.password.description = +thing-type.config.mediolaaiogateway.sample.refreshInterval.label = +thing-type.config.mediolaaiogateway.sample.refreshInterval.description = + +# channel types +channel-type.mediolaaiogateway.sample-channel.label = +channel-type.mediolaaiogateway.sample-channel.description = diff --git a/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/thing/thing-types.xml new file mode 100644 index 000000000..0afcb0a2d --- /dev/null +++ b/bundles/org.openhab.binding.mediolaaiogateway/src/main/resources/OH-INF/thing/thing-types.xml @@ -0,0 +1,46 @@ + + + + + + + + + Sample thing for MediolaAioGateway 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 MediolaAioGateway Binding + +