forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lcn] Add LCN binding (openhab#7509)
* [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
Showing
111 changed files
with
11,954 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
119 changes: 119 additions & 0 deletions
119
...enhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/DimmerOutputProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...openhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/ILcnModuleActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
43 changes: 43 additions & 0 deletions
43
...enhab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnBindingConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
26 changes: 26 additions & 0 deletions
26
...g.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnChannelVariableConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
25 changes: 25 additions & 0 deletions
25
...hab.binding.lcn/src/main/java/org/openhab/binding/lcn/internal/LcnGroupConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.