Skip to content

Commit

Permalink
[lcn] Add LCN binding (openhab#7509)
Browse files Browse the repository at this point in the history
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
  • Loading branch information
fwolter authored and andrewfg committed Aug 31, 2020
1 parent efffb73 commit f7d8556
Show file tree
Hide file tree
Showing 111 changed files with 11,954 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
/bundles/org.openhab.binding.konnected/ @volfan6415
/bundles/org.openhab.binding.kostalinverter/ @cschneider
/bundles/org.openhab.binding.lametrictime/ @syphr42
/bundles/org.openhab.binding.lcn/ @fwolter
/bundles/org.openhab.binding.leapmotion/ @kaikreuzer
/bundles/org.openhab.binding.lghombot/ @FluBBaOfWard
/bundles/org.openhab.binding.lgtvserial/ @fa2k
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@
<artifactId>org.openhab.binding.lametrictime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.lcn</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.leapmotion</artifactId>
Expand Down
32 changes: 32 additions & 0 deletions bundles/org.openhab.binding.lcn/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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-1.8">
<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 kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions bundles/org.openhab.binding.lcn/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.lcn</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>
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.lcn/NOTICE
Original file line number Diff line number Diff line change
@@ -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
594 changes: 594 additions & 0 deletions bundles/org.openhab.binding.lcn/README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundles/org.openhab.binding.lcn/doc/dyn_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundles/org.openhab.binding.lcn/doc/ir.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bundles/org.openhab.binding.lcn/doc/overview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions bundles/org.openhab.binding.lcn/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>2.5.6-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.lcn</artifactId>

<name>openHAB Add-ons :: Bundles :: LCN Binding</name>

</project>
9 changes: 9 additions & 0 deletions bundles/org.openhab.binding.lcn/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.lcn-${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-lcn" description="Lcn Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.lcn/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* 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.lcn.internal;

import java.math.BigDecimal;
import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.profiles.ProfileCallback;
import org.eclipse.smarthome.core.thing.profiles.ProfileContext;
import org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID;
import org.eclipse.smarthome.core.thing.profiles.StateProfile;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.lcn.internal.common.DimmerOutputCommand;
import org.openhab.binding.lcn.internal.common.LcnDefs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A profile to control multiple dimmer outputs simultaneously with ramp.
*
* @author Fabian Wolter - Initial Contribution
*/
@NonNullByDefault
public class DimmerOutputProfile implements StateProfile {
private final Logger logger = LoggerFactory.getLogger(DimmerOutputProfile.class);
/** The Profile's UID */
static final ProfileTypeUID UID = new ProfileTypeUID(LcnBindingConstants.BINDING_ID, "output");
private final ProfileCallback callback;
private int rampMs;
private boolean controlAllOutputs;
private boolean controlOutputs12;

public DimmerOutputProfile(ProfileCallback callback, ProfileContext profileContext) {
this.callback = callback;

Optional<Object> ramp = getConfig(profileContext, "ramp");
Optional<Object> allOutputs = getConfig(profileContext, "controlAllOutputs");
Optional<Object> outputs12 = getConfig(profileContext, "controlOutputs12");

ramp.ifPresent(b -> {
if (b instanceof BigDecimal) {
rampMs = (int) (((BigDecimal) b).doubleValue() * 1000);
} else {
logger.warn("Could not parse 'ramp', unexpected type, should be float: {}", ramp);
}
});

allOutputs.ifPresent(b -> {
if (b instanceof Boolean) {
controlAllOutputs = true;
} else {
logger.warn("Could not parse 'controlAllOutputs', unexpected type, should be true/false: {}", b);
}
});

outputs12.ifPresent(b -> {
if (b instanceof Boolean) {
controlOutputs12 = true;
} else {
logger.warn("Could not parse 'controlOutputs12', unexpected type, should be true/false: {}", b);
}
});
}

private Optional<Object> getConfig(ProfileContext profileContext, String key) {
return Optional.ofNullable(profileContext.getConfiguration().get(key));
}

@Override
public void onCommandFromItem(Command command) {
if (rampMs != 0 && rampMs != LcnDefs.FIXED_RAMP_MS && controlOutputs12) {
logger.warn("Unsupported 'ramp' setting. Will be forced to 250ms: {}", rampMs);
}
BigDecimal value;
if (command instanceof DecimalType) {
value = ((DecimalType) command).toBigDecimal();
} else if (command instanceof OnOffType) {
value = ((OnOffType) command) == OnOffType.ON ? BigDecimal.valueOf(100) : BigDecimal.ZERO;
} else {
logger.warn("Unsupported type: {}", command.toFullString());
return;
}
callback.handleCommand(new DimmerOutputCommand(value, controlAllOutputs, controlOutputs12, rampMs));
}

@Override
public void onStateUpdateFromHandler(State state) {
callback.sendUpdate(state);
}

@Override
public ProfileTypeUID getProfileTypeUID() {
return UID;
}

@Override
public void onCommandFromHandler(Command command) {
// nothing
}

@Override
public void onStateUpdateFromItem(State state) {
// nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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.lcn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link ILcnModuleActions} defines the interface for all thing actions supported by the binding.
* These methods, parameters, and return types are explained in {@link LcnModuleActions}.
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
public interface ILcnModuleActions {
void hitKey(@Nullable String table, int key, @Nullable String action);

void flickerOutput(int output, int depth, int ramp, int count);

void sendDynamicText(int row, @Nullable String textInput);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.lcn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.ThingTypeUID;

/**
* The {@link LcnBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
public class LcnBindingConstants {
/** The scope name of this binding */
public static final String BINDING_ID = "lcn";
/**
* Firmware version of the measurement processing since 2013. It has more variables and thresholds and event-based
* variable updates.
*/
public static final int FIRMWARE_2013 = 0x170206;
/** Firmware version which supports controlling all 4 outputs simultaneously */
public static final int FIRMWARE_2014 = 0x180501;
/** List of all Thing Type UIDs */
public static final ThingTypeUID THING_TYPE_PCK_GATEWAY = new ThingTypeUID(BINDING_ID, "pckGateway");
public static final ThingTypeUID THING_TYPE_MODULE = new ThingTypeUID(BINDING_ID, "module");
public static final ThingTypeUID THING_TYPE_GROUP = new ThingTypeUID(BINDING_ID, "group");
/** Regex for address in PCK protocol */
public static final String ADDRESS_REGEX = "[:=%]M(?<segId>\\d{3})(?<modId>\\d{3})";
/** LCN coding for ACK */
public static final int CODE_ACK = -1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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.lcn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link LcnChannelVariableConfiguration} class contains configuration field mapping for Channels of type
* 'variable'.
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
public class LcnChannelVariableConfiguration {
public String unit = "native";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.lcn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link LcnModuleConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Fabian Wolter - Initial contribution
*/
@NonNullByDefault
public class LcnGroupConfiguration extends LcnModuleConfiguration {
public int groupId;
}
Loading

0 comments on commit f7d8556

Please sign in to comment.