added migrated 2.x add-ons

Signed-off-by: Kai Kreuzer <kai@openhab.org>
This commit is contained in:
Kai Kreuzer
2020-09-21 01:58:32 +02:00
parent bbf1a7fd29
commit 6df6783b60
11662 changed files with 1302875 additions and 11 deletions

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.omnikinverter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -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

View File

@@ -0,0 +1,56 @@
# Omnik Inverter Binding
This binding reads metrics from Omnik Solar Inverters.
## Supported Things
All Omniksols are expected to function, provided they have the Wifi module. At
moment of writing the _Omniksol-3.0k-TL2_ has been tested.
## Discovery
No autodiscovery available
## Thing Configuration
| Config | Description | type | Default |
| :------- | :------------ | :----- | :-------- |
| hostname | The hostname or ip through which the inverter can be accessed | string | n/a |
| port | TCP port through which the inverter listens on for incoming connections | integer | 8899 |
| serial | The serial of the wifi module. The Wifi module's SSID contains the number. This is the numerical part only, i.e. without _AP__ | integer | n/a |
## Channels
| Channel Type Id | Item Type | Description |
| :---------------- | :---------- | :------------ |
| power | Number:Power | The instantaneous power generation |
| energyToday | Number:Energy | The amount of energy generated today |
| energyTotal | Number:Energy | The total amount of energy generated |
## Full Example
### demo.things
```
Thing omnikinverter:omnik:70ecb4f0 "Solar Inverter" [ hostname="igen-wifi.lan",serial=604455290]
```
### demo.items
```
Number OmnikInverterBindingThing_InstantaneousPower "Solar Power" {channel="omnikinverter:omnik:70ecb4f0:power"}
Number OmnikInverterBindingThing_TotalGeneratedEnergyToday "Solar Energy Today" {channel="omnikinverter:omnik:70ecb4f0:energyToday"}
Number OmnikInverterBindingThing_TotalGeneratedEnergy "Solar Energy Total" {channel="omnikinverter:omnik:70ecb4f0:energyTotal"}
```
### Sitemap
```
Text item=OmnikInverterBindingThing_InstantaneousPower
Text item=OmnikInverterBindingThing_TotalGeneratedEnergyToday label="Today"
Text item=OmnikInverterBindingThing_TotalGeneratedEnergy label="Total"
```
## References
Based on the work of https://github.com/Woutrrr/Omnik-Data-Logger

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.openhab.binding.omnikinverter</artifactId>
<name>openHAB Add-ons :: Bundles :: OmnikInverter Binding</name>
</project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.omnikinverter-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
<feature name="openhab-binding-omnikinverter" description="Omnik Inverter Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.omnikinverter/${project.version}</bundle>
</feature>
</features>

View File

@@ -0,0 +1,83 @@
/**
* 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.omnikinverter.internal;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import org.apache.commons.lang.ArrayUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
*
* @author Hans van den Bogert - Initial Contribution
*
*/
@NonNullByDefault
public class OmnikInverter {
private int serialNumber;
private String host;
private int port;
private byte[] magicPacket;
public OmnikInverter(String host, int port, int serialNumber) throws IOException {
this.host = host;
this.port = port;
this.serialNumber = serialNumber;
this.magicPacket = generateMagicPacket();
}
public OmnikInverterMessage pullCurrentStats() throws UnknownHostException, IOException {
byte[] magicPacket = this.magicPacket;
byte[] returnMessage = new byte[1024];
try (Socket socket = new Socket(host, port)) {
socket.setSoTimeout(5000);
socket.getOutputStream().write(magicPacket);
socket.getInputStream().read(returnMessage);
return new OmnikInverterMessage(returnMessage);
}
}
private byte[] generateMagicPacket() throws IOException {
byte[] magic = { 0x68, 0x02, 0x40, 0x30 };
ByteBuffer serialByteBuffer = ByteBuffer.allocate(8).putInt(serialNumber).putInt(serialNumber);
byte[] serialBytes = serialByteBuffer.array();
// Reverse serialBytes in a very mutable way.
ArrayUtils.reverse(serialBytes);
byte checksumCount = 115;
for (byte b : serialBytes) {
checksumCount += (char) b;
}
byte[] checksum = ByteBuffer.allocate(1).put(checksumCount).array();
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
outputStream.write(magic);
outputStream.write(serialBytes);
outputStream.write(0x01);
outputStream.write(0x00);
outputStream.write(checksum);
outputStream.write(0x16);
return outputStream.toByteArray();
}
}
}

View File

@@ -0,0 +1,38 @@
/**
* 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.omnikinverter.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;
/**
* The {@link OmnikInverterBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Hans van den Bogert - Initial contribution
*/
@NonNullByDefault
public class OmnikInverterBindingConstants {
private static final String BINDING_ID = "omnikinverter";
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_OMNIK = new ThingTypeUID(BINDING_ID, "omnik");
// List of all Channel ids
public static final String CHANNEL_POWER = "power";
public static final String CHANNEL_ENERGY_TODAY = "energyToday";
public static final String CHANNEL_ENERGY_TOTAL = "energyTotal";
}

View File

@@ -0,0 +1,27 @@
/**
* 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.omnikinverter.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* The {@link OmnikInverterConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Hans van den Bogert - Initial contribution
*/
@NonNullByDefault
public class OmnikInverterConfiguration {
public String hostname = "";
public int port;
public int serial;
}

View File

@@ -0,0 +1,57 @@
/**
* 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.omnikinverter.internal;
import static org.openhab.binding.omnikinverter.internal.OmnikInverterBindingConstants.THING_TYPE_OMNIK;
import java.util.Collections;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.omnikinverter.internal.handler.OmnikInverterHandler;
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 OmnikInverterHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Hans van den Bogert - Initial contribution
*/
@NonNullByDefault
@Component(configurationPid = "binding.omnikinverter", service = ThingHandlerFactory.class)
public class OmnikInverterHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_OMNIK);
@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_OMNIK.equals(thingTypeUID)) {
return new OmnikInverterHandler(thing);
}
return null;
}
}

View File

@@ -0,0 +1,61 @@
/**
* 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.omnikinverter.internal;
import java.nio.ByteBuffer;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
*
* @author Hans van den Bogert - Initial contribution
*
*/
@NonNullByDefault
public class OmnikInverterMessage {
private final byte[] bytes;
public OmnikInverterMessage(byte[] b) {
this.bytes = b;
}
public double getPower() {
ByteBuffer buf = ByteBuffer.allocate(2);
buf.put(bytes, 59, 2);
buf.rewind();
return buf.getShort();
}
/**
*
* @return the total energy outputted this day in kWh
*/
public double getEnergyToday() {
ByteBuffer buf = ByteBuffer.allocate(2);
buf.put(bytes, 69, 2);
buf.rewind();
return (buf.getShort() / 100.0);
}
/**
*
* @return the total energy outputted in kWh
*/
public double getTotalEnergy() {
ByteBuffer buf = ByteBuffer.allocate(4);
buf.put(bytes, 71, 4);
buf.rewind();
return buf.getInt() / 10.0;
}
}

View File

@@ -0,0 +1,103 @@
/**
* 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.omnikinverter.internal.handler;
import java.io.IOException;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import javax.measure.quantity.Power;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.omnikinverter.internal.OmnikInverter;
import org.openhab.binding.omnikinverter.internal.OmnikInverterBindingConstants;
import org.openhab.binding.omnikinverter.internal.OmnikInverterConfiguration;
import org.openhab.binding.omnikinverter.internal.OmnikInverterMessage;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.SmartHomeUnits;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
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 OmnikInverterHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Hans van den Bogert - Initial contribution
*/
@NonNullByDefault
public class OmnikInverterHandler extends BaseThingHandler {
private @Nullable OmnikInverter inverter;
private final Logger logger = LoggerFactory.getLogger(OmnikInverterHandler.class);
public OmnikInverterHandler(Thing thing) {
super(thing);
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (OmnikInverterBindingConstants.CHANNEL_POWER.equals(channelUID.getId())) {
if (command instanceof RefreshType) {
updateData();
}
}
}
@Override
public void initialize() {
OmnikInverterConfiguration config = getConfigAs(OmnikInverterConfiguration.class);
try {
inverter = new OmnikInverter(config.hostname, config.port, config.serial);
scheduler.scheduleWithFixedDelay(this::updateData, 0, 10, TimeUnit.SECONDS);
} catch (IOException e) {
logger.debug("Could not instantiate OmnikInverter object: {}", e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR,
"Failed to initialize: " + e.getMessage());
}
}
private void updateData() {
try {
if (inverter != null) {
OmnikInverterMessage message = inverter.pullCurrentStats();
updateStatus(ThingStatus.ONLINE);
QuantityType<Power> powerQuantity = new QuantityType<>(message.getPower(), SmartHomeUnits.WATT);
updateState(OmnikInverterBindingConstants.CHANNEL_POWER, powerQuantity);
updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TODAY,
new QuantityType<>(message.getEnergyToday(), SmartHomeUnits.KILOWATT_HOUR));
updateState(OmnikInverterBindingConstants.CHANNEL_ENERGY_TOTAL,
new QuantityType<>(message.getTotalEnergy(), SmartHomeUnits.KILOWATT_HOUR));
}
} catch (UnknownHostException | NoRouteToHostException | ConnectException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (IOException e) {
logger.debug("Unknown exception when pulling data from the inverter: {}", e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Unknown error: " + e.getMessage());
}
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="omnikinverter" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:binding="https://openhab.org/schemas/binding/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd">
<name>OmnikInverter Binding</name>
<description>This is the binding for the Omnik solar grid inverters. The integration is based on the undocumented API,
which is reverse engineered at https://github.com/Woutrrr/Omnik-Data-Logger. As such, the known supported inverters
are known to work with inverters with wifi bridge which start with the serial number '602' and '606'.</description>
<author>Hans van den Bogert</author>
</binding:binding>

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="omnikinverter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
<thing-type id="omnik">
<label>OmnikInverter Binding Thing</label>
<description>Thing for OmnikInverter Binding</description>
<channels>
<channel id="power" typeId="power"/>
<channel id="energyToday" typeId="energyToday"/>
<channel id="energyTotal" typeId="energyTotal"/>
</channels>
<config-description>
<parameter name="hostname" type="text" required="true">
<label>Hostname</label>
<description>The hostname or IP of the Omnik Inverter</description>
<context>network-address</context>
</parameter>
<parameter name="port" type="integer" required="true">
<label>Port</label>
<description>The TCP port of the Omnik inverter, usually 8899</description>
<default>8899</default>
</parameter>
<parameter name="serial" type="integer" required="true">
<label>Serial</label>
<description>The serial of the Omnik inverter's Wifi module. This the number part only.</description>
</parameter>
</config-description>
</thing-type>
<channel-type id="power">
<item-type>Number:Power</item-type>
<label>Instantaneous Power</label>
<description>The instantaneous power generation</description>
<state readOnly="true" pattern="%.1f %unit%"/>
</channel-type>
<channel-type id="energyToday">
<item-type>Number:Energy</item-type>
<label>Energy Today</label>
<description>The amount of energy generated today</description>
<state readOnly="true" pattern="%.2f %unit%"/>
</channel-type>
<channel-type id="energyTotal">
<item-type>Number:Energy</item-type>
<label>Total Generated Energy</label>
<description>The amount of generated energy in total</description>
<state readOnly="true" pattern="%.2f %unit%"/>
</channel-type>
</thing:thing-descriptions>

View File

@@ -0,0 +1,52 @@
/**
* 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.omnikinverter.internal.test;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.Before;
import org.junit.Test;
import org.openhab.binding.omnikinverter.internal.OmnikInverterMessage;
/**
* @author Hans van den Bogert - Initial contribution
*/
public class OmnikInverterMessageTest {
private OmnikInverterMessage message;
@Before
public void setUp() throws IOException {
File file = new File("src/test/resources/omnik.output");
message = new OmnikInverterMessage(Files.readAllBytes(file.toPath()));
}
@Test
public void testGetPower() {
assertEquals(137.0, message.getPower(), 0.01);
}
@Test
public void testGetTotalEnergy() {
assertEquals(12412.7, message.getTotalEnergy(), 0.01);
}
@Test
public void testGetEnergyToday() {
assertEquals(11.13, message.getEnergyToday(), 0.01);
}
}