From 687558691c7dbd040de6c27b9883ef98c9441daa Mon Sep 17 00:00:00 2001 From: lewei50 Date: Mon, 7 Sep 2020 02:46:46 +0800 Subject: [PATCH] [iammeter] Iammeter Binding initial contribution (#8252) Signed-off-by: Yang Bo --- bom/openhab-addons/pom.xml | 5 + .../org.openhab.binding.iammeter/.classpath | 15 +++ bundles/org.openhab.binding.iammeter/.project | 23 ++++ bundles/org.openhab.binding.iammeter/NOTICE | 13 ++ .../org.openhab.binding.iammeter/README.md | 57 ++++++++ bundles/org.openhab.binding.iammeter/pom.xml | 17 +++ .../src/main/feature/feature.xml | 9 ++ .../internal/Iammeter3080THandler.java | 64 +++++++++ .../internal/IammeterBaseHandler.java | 126 ++++++++++++++++++ .../internal/IammeterBindingConstants.java | 32 +++++ .../internal/IammeterConfiguration.java | 30 +++++ .../iammeter/internal/IammeterHandler.java | 58 ++++++++ .../internal/IammeterHandlerFactory.java | 62 +++++++++ .../internal/IammeterWEM3080Channel.java | 48 +++++++ .../internal/IammeterWEM3080TChannel.java | 50 +++++++ .../resources/ESH-INF/binding/binding.xml | 10 ++ .../main/resources/ESH-INF/config/config.xml | 36 +++++ .../src/main/resources/ESH-INF/thing/3080.xml | 51 +++++++ .../main/resources/ESH-INF/thing/3080T.xml | 81 +++++++++++ bundles/pom.xml | 1 + 20 files changed, 788 insertions(+) create mode 100644 bundles/org.openhab.binding.iammeter/.classpath create mode 100644 bundles/org.openhab.binding.iammeter/.project create mode 100644 bundles/org.openhab.binding.iammeter/NOTICE create mode 100644 bundles/org.openhab.binding.iammeter/README.md create mode 100644 bundles/org.openhab.binding.iammeter/pom.xml create mode 100644 bundles/org.openhab.binding.iammeter/src/main/feature/feature.xml create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/Iammeter3080THandler.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBaseHandler.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBindingConstants.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterConfiguration.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandlerFactory.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080Channel.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080TChannel.java create mode 100644 bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/binding/binding.xml create mode 100644 bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/config/config.xml create mode 100644 bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080.xml create mode 100644 bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080T.xml diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index b59350765e7ca..9df2693015e63 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -426,6 +426,11 @@ org.openhab.binding.hyperion ${project.version} + + org.openhab.addons.bundles + org.openhab.binding.iammeter + ${project.version} + org.openhab.addons.bundles org.openhab.binding.iaqualink diff --git a/bundles/org.openhab.binding.iammeter/.classpath b/bundles/org.openhab.binding.iammeter/.classpath new file mode 100644 index 0000000000000..434c0f84169c7 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.iammeter/.project b/bundles/org.openhab.binding.iammeter/.project new file mode 100644 index 0000000000000..e0a44d3668856 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/.project @@ -0,0 +1,23 @@ + + + org.openhab.binding.iammeter + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/bundles/org.openhab.binding.iammeter/NOTICE b/bundles/org.openhab.binding.iammeter/NOTICE new file mode 100644 index 0000000000000..38d625e349232 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/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.iammeter/README.md b/bundles/org.openhab.binding.iammeter/README.md new file mode 100644 index 0000000000000..a23f85fd946a6 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/README.md @@ -0,0 +1,57 @@ +# Iammeter Binding + +[Iammeter](https://www.iammeter.com) provides real-time readings of single-phase (WEM3080, WEM3162) and three-phase (WEM3080T) meters from IAMMETER over Wi-Fi. + +## Use of the binding + +The Iammeter is exposed as one thing with a number of channels that can be used to read the values for different aspects of your Iammeter devices. + +## Setup of the binding + +You can add the Iammeter device via the openHAB UI manually. + + +## Available channels + +The following table is taken from the official manual and contains all available channels. + +Single-phase energy meter (WEM3080/WEM3162) +| Name | Unit | Description | Type | +|----------------|------|------------------------------|--------------------------| +| voltage_a | V | Voltage | Number:ElectricPotential | +| current_a | A | Current | Number:ElectricCurrent | +| power_a | W | Active power | Number:Power | +| importenergy_a | kWh | Energy consumption from gird | Number:Energy | +| exportgrid_a | kWh | Energy export to grid | Number:Energy | + + +Three-phase energy meter (WEM3080T) +| Name | Unit | Description | Type | +|----------------|------|-----------------------|--------------------------| +| voltage_a | V | A phase voltage | Number:ElectricPotential | +| current_a | A | A phase current | Number:ElectricCurrent | +| power_a | W | A phase active power | Number:Power | +| importenergy_a | kWh | A phase import energy | Number:Energy | +| exportgrid_a | kWh | A phase export energy | Number:Energy | +| frequency_a | kWh | A phase frequency | Number:Frequency | +| pf_a | kWh | A phase power factor | Number | +| voltage_b | V | B phase voltage | Number:ElectricPotential | +| current_b | A | B phase current | Number:ElectricCurrent | +| power_b | W | B phase active power | Number:Power | +| importenergy_b | kWh | B phase import energy | Number:Energy | +| exportgrid_b | kWh | B phase export energy | Number:Energy | +| frequency_b | kWh | B phase frequency | Number:Frequency | +| pf_b | kWh | B phase power factor | Number | +| voltage_c | V | C phase voltage | Number:ElectricPotential | +| current_c | A | C phase current | Number:ElectricCurrent | +| power_c | W | C phase active power | Number:Power | +| importenergy_c | kWh | C phase import energy | Number:Energy | +| exportgrid_c | kWh | C phase export energy | Number:Energy | +| frequency_c | kWh | C phase frequency | Number:Frequency | +| pf_c | kWh | C phase power factor | Number | + + + +## More information + +More information about the Iammeter devices can be found in the [Iammeter website](https://www.iammeter.com). diff --git a/bundles/org.openhab.binding.iammeter/pom.xml b/bundles/org.openhab.binding.iammeter/pom.xml new file mode 100644 index 0000000000000..a2eee13e916fe --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + 2.5.9-SNAPSHOT + + + org.openhab.binding.iammeter + + openHAB Add-ons :: Bundles :: Iammeter Binding + + diff --git a/bundles/org.openhab.binding.iammeter/src/main/feature/feature.xml b/bundles/org.openhab.binding.iammeter/src/main/feature/feature.xml new file mode 100644 index 0000000000000..113a32aca1d3f --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/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.iammeter/${project.version} + + diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/Iammeter3080THandler.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/Iammeter3080THandler.java new file mode 100644 index 0000000000000..7c573f8603628 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/Iammeter3080THandler.java @@ -0,0 +1,64 @@ +/** + * 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.iammeter.internal; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.thing.Channel; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.types.State; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +/** + * The {@link IammeterHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Yang Bo - Initial contribution + */ + +@NonNullByDefault +public class Iammeter3080THandler extends IammeterBaseHandler { + + public Iammeter3080THandler(Thing thing) { + super(thing); + } + + @SuppressWarnings("null") + @Override + protected void resolveData(String response) { + JsonElement iammeterDataElement = new JsonParser().parse(response); + JsonObject iammeterData = iammeterDataElement.getAsJsonObject(); + String keyWord = "Datas"; + if (iammeterData.has("Datas") && iammeterData.has("SN")) { + String groups[] = { "powerPhaseA", "powerPhaseB", "powerPhaseC" }; + for (int row = 0; row < groups.length; row++) { + String gpName = groups[row]; + List chnList = getThing().getChannelsOfGroup(gpName); + for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) { + Channel chnl = chnList.get(channelConfig.ordinal()); + if (chnl != null) { + State state = getQuantityState(iammeterData.get(keyWord).getAsJsonArray().get(row) + .getAsJsonArray().get(channelConfig.ordinal()).toString(), channelConfig.getUnit()); + updateState(chnl.getUID(), state); + } + } + updateStatus(ThingStatus.ONLINE); + } + } + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBaseHandler.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBaseHandler.java new file mode 100644 index 0000000000000..c488ecc6773df --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBaseHandler.java @@ -0,0 +1,126 @@ +/** + * 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.iammeter.internal; + +import java.io.IOException; +import java.time.Duration; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import javax.measure.Unit; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.cache.ExpiringCache; +import org.eclipse.smarthome.core.library.types.QuantityType; +import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingStatus; +import org.eclipse.smarthome.core.thing.ThingStatusDetail; +import org.eclipse.smarthome.core.thing.binding.BaseThingHandler; +import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.RefreshType; +import org.eclipse.smarthome.core.types.State; +import org.eclipse.smarthome.core.types.UnDefType; +import org.eclipse.smarthome.io.net.http.HttpUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.JsonSyntaxException; + +/** + * The {@link IammeterHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Yang Bo - Initial contribution + */ + +@NonNullByDefault +public abstract class IammeterBaseHandler extends BaseThingHandler { + + private final Logger logger = LoggerFactory.getLogger(IammeterBaseHandler.class); + private @Nullable ScheduledFuture refreshJob; + private IammeterConfiguration config; + private static final int TIMEOUT_MS = 5000; + private final ExpiringCache refreshCache = new ExpiringCache<>(Duration.ofSeconds(5), this::refresh); + + public IammeterBaseHandler(Thing thing) { + super(thing); + config = getConfiguration(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (command instanceof RefreshType) { + refreshCache.getValue(); + } + } + + @Override + public void initialize() { + ScheduledFuture refreshJob = this.refreshJob; + config = getConfiguration(); + if (refreshJob == null) { + refreshJob = scheduler.scheduleWithFixedDelay(this::refresh, 0, config.refreshInterval, TimeUnit.SECONDS); + this.refreshJob = refreshJob; + updateStatus(ThingStatus.UNKNOWN); + } + } + + protected abstract void resolveData(String response); + + @SuppressWarnings("null") + private boolean refresh() { + refreshCache.invalidateValue(); + IammeterConfiguration config = this.config; + try { + String httpMethod = "GET"; + String url = "http://" + config.username + ":" + config.password + "@" + config.host + ":" + config.port + + "/monitorjson"; + String response = HttpUtil.executeUrl(httpMethod, url, TIMEOUT_MS); + resolveData(response); + updateStatus(ThingStatus.ONLINE); + return true; + // Very rudimentary Exception differentiation + } catch (IOException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Communication error with the device: " + e.getMessage()); + } catch (JsonSyntaxException je) { + logger.warn("Invalid JSON when refreshing source {}: {}", getThing().getUID(), je.getMessage()); + updateStatus(ThingStatus.OFFLINE); + } + return false; + } + + protected State getQuantityState(String value, Unit unit) { + try { + return QuantityType.valueOf(Float.parseFloat(value), unit); + } catch (NumberFormatException e) { + return UnDefType.UNDEF; + } + } + + @Override + public void dispose() { + ScheduledFuture refreshJob = this.refreshJob; + if (refreshJob != null && !refreshJob.isCancelled()) { + refreshJob.cancel(true); + this.refreshJob = null; + } + super.dispose(); + } + + public IammeterConfiguration getConfiguration() { + return this.getConfigAs(IammeterConfiguration.class); + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBindingConstants.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBindingConstants.java new file mode 100644 index 0000000000000..9da0493c73aeb --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterBindingConstants.java @@ -0,0 +1,32 @@ +/** + * 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.iammeter.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.thing.ThingTypeUID; + +/** + * The {@link IammeterBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author yang bo - Initial contribution + */ +@NonNullByDefault +public class IammeterBindingConstants { + + public static final String BINDING_ID = "iammeter"; + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_POWERMETER = new ThingTypeUID(BINDING_ID, "powermeter"); + public static final ThingTypeUID THING_TYPE_POWERMETER_3080T = new ThingTypeUID(BINDING_ID, "powermeter3080T"); +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterConfiguration.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterConfiguration.java new file mode 100644 index 0000000000000..066951e17e4c0 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterConfiguration.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.iammeter.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link IammeterConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Yang Bo - Initial contribution + */ + +@NonNullByDefault +public class IammeterConfiguration { + public String host = "127.0.0.1"; + public int port = 80; + public int refreshInterval = 30; + public String username = "admin"; + public String password = "admin"; +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java new file mode 100644 index 0000000000000..b232c4f2d9244 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java @@ -0,0 +1,58 @@ +/** + * 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.iammeter.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.thing.Channel; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.types.State; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +/** + * The {@link IammeterHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Yang Bo - Initial contribution + */ + +@NonNullByDefault +public class IammeterHandler extends IammeterBaseHandler { + + public IammeterHandler(Thing thing) { + super(thing); + } + + @Override + protected void resolveData(String response) { + JsonElement iammeterDataElement = new JsonParser().parse(response); + JsonObject iammeterData = iammeterDataElement.getAsJsonObject(); + String keyWord = "Data"; + if (iammeterData.has("data") || (iammeterData.has("Data") && iammeterData.has("SN"))) { + if (iammeterData.has("data")) { + keyWord = "data"; + } + for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) { + Channel channel = getThing().getChannel(channelConfig.getId()); + if (channel != null) { + State state = getQuantityState( + iammeterData.get(keyWord).getAsJsonArray().get(channelConfig.ordinal()).toString(), + channelConfig.getUnit()); + updateState(channel.getUID(), state); + } + } + } + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandlerFactory.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandlerFactory.java new file mode 100644 index 0000000000000..9ea60428de213 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandlerFactory.java @@ -0,0 +1,62 @@ +/** + * 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.iammeter.internal; + +import static org.openhab.binding.iammeter.internal.IammeterBindingConstants.*; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.ThingTypeUID; +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.osgi.service.component.annotations.Component; + +/** + * The {@link IammeterHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Yang Bo - Initial contribution + */ +@NonNullByDefault +@Component(configurationPid = "binding.iammeter", service = ThingHandlerFactory.class) +public class IammeterHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = new HashSet<>(); + static { + SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_POWERMETER); + SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_POWERMETER_3080T); + } + + @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_POWERMETER.equals(thingTypeUID)) { + return new IammeterHandler(thing); + } else if (THING_TYPE_POWERMETER_3080T.equals(thingTypeUID)) { + return new Iammeter3080THandler(thing); + } + + return null; + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080Channel.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080Channel.java new file mode 100644 index 0000000000000..7d5ccdd900176 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080Channel.java @@ -0,0 +1,48 @@ +/** + * 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.iammeter.internal; + +import javax.measure.Unit; + +import org.eclipse.smarthome.core.library.unit.SmartHomeUnits; + +/** + * The {@link IammeterWEM3080Channel} Enum defines common constants, which are + * used across the whole binding. + * + * @author Yang Bo - Initial contribution + */ +public enum IammeterWEM3080Channel { + + CHANNEL_VOLTAGE("voltage", SmartHomeUnits.VOLT), + CHANNEL_CURRENT("current", SmartHomeUnits.AMPERE), + CHANNEL_POWER("power", SmartHomeUnits.WATT), + CHANNEL_IMPORTENERGY("importenergy", SmartHomeUnits.KILOWATT_HOUR), + CHANNEL_EXPORTGRID("exportgrid", SmartHomeUnits.KILOWATT_HOUR); + + private final String id; + private final Unit unit; + + IammeterWEM3080Channel(String id, Unit unit) { + this.id = id; + this.unit = unit; + } + + public String getId() { + return id; + } + + public Unit getUnit() { + return unit; + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080TChannel.java b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080TChannel.java new file mode 100644 index 0000000000000..ad32c3b5d65a0 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080TChannel.java @@ -0,0 +1,50 @@ +/** + * 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.iammeter.internal; + +import javax.measure.Unit; + +import org.eclipse.smarthome.core.library.unit.SmartHomeUnits; + +/** + * The {@link IammeterWEM3080TChannel} Enum defines common constants, which are + * used across the whole binding. + * + * @author Yang Bo - Initial contribution + */ +public enum IammeterWEM3080TChannel { + + CHANNEL_VOLTAGE("voltage", SmartHomeUnits.VOLT), + CHANNEL_CURRENT("current", SmartHomeUnits.AMPERE), + CHANNEL_POWER("power", SmartHomeUnits.WATT), + CHANNEL_IMPORTENERGY("importenergy", SmartHomeUnits.KILOWATT_HOUR), + CHANNEL_EXPORTGRID("exportgrid", SmartHomeUnits.KILOWATT_HOUR), + CHANNEL_FREQUENCY("frequency", SmartHomeUnits.HERTZ), + CHANNEL_PF("pf", SmartHomeUnits.HERTZ); + + private final String id; + private final Unit unit; + + IammeterWEM3080TChannel(String id, Unit unit) { + this.id = id; + this.unit = unit; + } + + public String getId() { + return id; + } + + public Unit getUnit() { + return unit; + } +} diff --git a/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/binding/binding.xml b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/binding/binding.xml new file mode 100644 index 0000000000000..05e1d392b0743 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/binding/binding.xml @@ -0,0 +1,10 @@ + + + + Iammeter Binding + The Iammeter binding pull your Iammeter power meter data from LAN. + Yang Bo + + diff --git a/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/config/config.xml b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/config/config.xml new file mode 100644 index 0000000000000..788cc1ae5adf4 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/config/config.xml @@ -0,0 +1,36 @@ + + + + + + + IP address for your device + network-address + 127.0.0.1 + + + + Port + 80 + + + + User name to access device + admin + + + + password to access device + password + admin + + + + 60 + + + + diff --git a/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080.xml b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080.xml new file mode 100644 index 0000000000000..d0224b85f2632 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080.xml @@ -0,0 +1,51 @@ + + + + + + Single phase PowerMeter for Iammeter Binding + + + + + + + + + + + + Number:ElectricPotential + + voltage for phase A + + + + Number:ElectricCurrent + + current for phase A + + + + Number:Power + + power for phase A + + + + Number:Energy + + importenergy for phase A + + + + Number:Energy + + exportgrid for phase A + + + + diff --git a/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080T.xml b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080T.xml new file mode 100644 index 0000000000000..c26d409f3f1a8 --- /dev/null +++ b/bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080T.xml @@ -0,0 +1,81 @@ + + + + + + 3 phases PowerMeter for Iammeter 3080T Binding + + + + Power phase 1 for Iammeter device + + + + Power phase 2 for Iammeter device + + + + Power phase 3 for Iammeter device + + + + + + + + + + + + + + + + + + Number:ElectricPotential + + voltage for phase A + + + + Number:ElectricCurrent + + current for phase A + + + + Number:Power + + power for phase A + + + + Number:Energy + + importenergy for phase A + + + + Number:Energy + + exportgrid for phase A + + + + Number:Frequency + + frequency for phase A + + + + Number + + power factor for phase A + + + + diff --git a/bundles/pom.xml b/bundles/pom.xml index fba3f349fc960..c2ecb54410610 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -122,6 +122,7 @@ org.openhab.binding.hue org.openhab.binding.hydrawise org.openhab.binding.hyperion + org.openhab.binding.iammeter org.openhab.binding.iaqualink org.openhab.binding.icalendar org.openhab.binding.icloud