mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
[dolbycp] Initial Contribution (#16216)
* Added new binding dolbycp Signed-off-by: Roland Tapken <dev@cybso.de>
This commit is contained in:
parent
d72c5b565b
commit
0745cdbfbb
@ -77,6 +77,7 @@
|
||||
/bundles/org.openhab.binding.digitalstrom/ @openhab/add-ons-maintainers
|
||||
/bundles/org.openhab.binding.dlinksmarthome/ @MikeJMajor
|
||||
/bundles/org.openhab.binding.dmx/ @openhab/add-ons-maintainers
|
||||
/bundles/org.openhab.binding.dolbycp/ @Cybso
|
||||
/bundles/org.openhab.binding.dominoswiss/ @Friesoch
|
||||
/bundles/org.openhab.binding.doorbird/ @mhilbush
|
||||
/bundles/org.openhab.binding.draytonwiser/ @andrew-schofield
|
||||
|
@ -376,6 +376,11 @@
|
||||
<artifactId>org.openhab.binding.dmx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.dolbycp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openhab.addons.bundles</groupId>
|
||||
<artifactId>org.openhab.binding.dominoswiss</artifactId>
|
||||
|
25
bundles/org.openhab.binding.dolbycp/NOTICE
Normal file
25
bundles/org.openhab.binding.dolbycp/NOTICE
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
||||
|
||||
== Third Party Dependencies
|
||||
Third Party Dependencies are used inside the code of this project, but not
|
||||
redistributed. Instead, Openhab retrieves the dependencies directly from
|
||||
public sources.
|
||||
|
||||
=== de.cybso.cp750:cp750
|
||||
Author: Roland Tapken
|
||||
URL: https://github.com/cybso/cp750-java
|
||||
License: Apache License Version 2.0
|
||||
|
||||
|
91
bundles/org.openhab.binding.dolbycp/README.md
Normal file
91
bundles/org.openhab.binding.dolbycp/README.md
Normal file
@ -0,0 +1,91 @@
|
||||
# DolbyCP Binding
|
||||
|
||||
This binding is intended to connect to a _Dolby Digital Cinema Processor CP750_.
|
||||
Support for CP950 may be added in future (if someone who owns one helps to test it).
|
||||
|
||||
It uses ASCII commands send over a TCP connection on port 61408.
|
||||
Please note that the CP750 only accepts up to 20 simultaneous connection and will discard the oldest connection if a 21st connection is established.
|
||||
So be sure to grateful shutdown each connection using the client's close() method, or it's AutoCloseable functionality.
|
||||
|
||||
This binding wraps the CP750 Java library from https://github.com/Cybso/cp750-java/.
|
||||
|
||||
This project is NOT affiliated with, funded, or in any way associated with Dolby Laboratories, Inc.
|
||||
|
||||
## Supported Things
|
||||
|
||||
- `cp750` - The Dolby Digital Cinema Processor CP750 Device.
|
||||
|
||||
## Thing Configuration
|
||||
|
||||
Normally, only the hostname or IP address must be configured.
|
||||
|
||||
### `cp750` Thing Configuration
|
||||
|
||||
| Name | Type | Description | Default | Required | Advanced |
|
||||
|-------------------|---------|--------------------------------------------------------------|---------|----------|----------|
|
||||
| hostname | text | Hostname or IP address of the device | N/A | yes | no |
|
||||
| port | integer | TCP port if different from 61408 | 61408 | no | no |
|
||||
| refreshInterval | integer | Interval the device is polled in seconds | 5 | no | no |
|
||||
| reconnectInterval | integer | Interval a new connection is tried after IO error in seconds | 10 | no | no |
|
||||
|
||||
## Properties
|
||||
|
||||
| Name | Description |
|
||||
|-------------------|----------------------------------------------------------|
|
||||
| osVersion | The operating system's version as returned by the device |
|
||||
|
||||
## Channels
|
||||
|
||||
These channels can be used to retrieve the current device state and change the controls.
|
||||
|
||||
The input mode can be either be controlled by the "input" string channel, or by writing an ON value to the dedicated switch channels, which represents the physical buttons on the CP750 device.
|
||||
|
||||
| Channel | Type | Read/Write | Description |
|
||||
|------------|--------|------------|-----------------------------------------------------------------------------------------------------------------|
|
||||
| fader | Dimmer | RW | Fader value (0 to 100) |
|
||||
| mute | Switch | RW | Mute (ON or OFF) |
|
||||
| input | String | RW | Input channel as string (one of "analog", "dig_1", "dig_2", "dig_3", "dig_4", "non-sync" or "mic") |
|
||||
| analog | Switch | RW | Is ON if input mode is 'analog'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| dig1 | Switch | RW | Is ON if input mode is 'dig_1'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| dig2 | Switch | RW | Is ON if input mode is 'dig_2'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| dig3 | Switch | RW | Is ON if input mode is 'dig_3'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| dig4 | Switch | RW | Is ON if input mode is 'dig_4'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| nonsync | Switch | RW | Is ON if input mode is 'non-sync'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
| mic | Switch | RW | Is ON if input mode is 'mic'. When an ON command is retrieved, input mode will be changed to this channel. |
|
||||
|
||||
## Full Example
|
||||
|
||||
The following example is for a device connected at IP 192.168.1.135 on port 61408 with all channels linked to items.
|
||||
|
||||
demo.things:
|
||||
|
||||
```java
|
||||
Thing dolbycp:cp750:myCp750 "CP750" @ "Projector Room" [hostname="192.168.1.135", port=61408, refreshInterval=5, reconnectInterval=10] {
|
||||
Channels:
|
||||
Type fader : myFader "Fader control"
|
||||
Type mute : myMute "Mute control"
|
||||
Type input : myInput "Input mode control"
|
||||
Type analog : myAnalogBtn "Input Mode 'analog' switch control"
|
||||
Type dig1 : myDig1Btn "Input Mode 'Digital 1' switch control"
|
||||
Type dig2 : myDig2Btn "Input Mode 'Digital 2' switch control"
|
||||
Type dig3 : myDig3Btn "Input Mode 'Digital 3' switch control"
|
||||
Type dig4 : myDig4Btn "Input Mode 'Digital 4' switch control"
|
||||
Type nonsync : myNonSyncBtn "Input Mode 'Non-Sync' switch control"
|
||||
Type mic : myMicBtn "Input Mode 'Microphone' switch control"
|
||||
}
|
||||
```
|
||||
|
||||
demo.items:
|
||||
|
||||
```java
|
||||
Dimmer mycp750_volume "Volume [%d]" { channel="dolbycp:cp750:myCp750:myFader" }
|
||||
Switch mycp750_mute "Mute" { channel="dolbycp:cp750:myCp750:myMute" }
|
||||
String mycp750_input "Input Mode [%s]" { channel="dolbycp:cp750:myCp750:myInput" }
|
||||
Switch mycp750_analog "Input Mode Analog" { channel="dolbycp:cp750:myCp750:myAnalogBtn" }
|
||||
Switch mycp750_dig1 "Input Mode Digital 1" { channel="dolbycp:cp750:myCp750:myDig1Btn" }
|
||||
Switch mycp750_dig2 "Input Mode Digital 2" { channel="dolbycp:cp750:myCp750:myDig2Btn" }
|
||||
Switch mycp750_dig3 "Input Mode Digital 3" { channel="dolbycp:cp750:myCp750:myDig3Btn" }
|
||||
Switch mycp750_dig4 "Input Mode Digital 4" { channel="dolbycp:cp750:myCp750:myDig4Btn" }
|
||||
Switch mycp750_nonsyc "Input Mode Non-Sync" { channel="dolbycp:cp750:myCp750:myNonSyncBtn" }
|
||||
Switch mycp750_mic "Input Mode Microphone" { channel="dolbycp:cp750:myCp750:myMicBtn" }
|
||||
```
|
26
bundles/org.openhab.binding.dolbycp/pom.xml
Normal file
26
bundles/org.openhab.binding.dolbycp/pom.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?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 https://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>4.2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>org.openhab.binding.dolbycp</artifactId>
|
||||
|
||||
<name>openHAB Add-ons :: Bundles :: Dolby Cinema Processor Binding</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.cybso.cp750</groupId>
|
||||
<artifactId>cp750</artifactId>
|
||||
<version>0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<features name="org.openhab.binding.dolbycp-${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-dolbycp" description="DolbyCP Binding" version="${project.version}">
|
||||
<feature>openhab-runtime-base</feature>
|
||||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.dolbycp/${project.version}</bundle>
|
||||
</feature>
|
||||
</features>
|
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2024 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.dolbycp.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.thing.ThingTypeUID;
|
||||
|
||||
/**
|
||||
* The {@link DolbyCPBindingConstants} class defines common constants, which are
|
||||
* used across the whole binding.
|
||||
*
|
||||
* @author Roland Tapken - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DolbyCPBindingConstants {
|
||||
|
||||
private static final String BINDING_ID = "dolbycp";
|
||||
|
||||
// List of all Thing Type UIDs
|
||||
public static final ThingTypeUID THING_TYPE_SAMPLE = new ThingTypeUID(BINDING_ID, "cp750");
|
||||
|
||||
// List of all Channel ids
|
||||
public static final String CHANNEL_FADER = "fader";
|
||||
public static final String CHANNEL_MUTE = "mute";
|
||||
public static final String CHANNEL_INPUT = "input";
|
||||
public static final String CHANNEL_ANALOG = "analog";
|
||||
public static final String CHANNEL_DIG1 = "dig1";
|
||||
public static final String CHANNEL_DIG2 = "dig2";
|
||||
public static final String CHANNEL_DIG3 = "dig3";
|
||||
public static final String CHANNEL_DIG4 = "dig4";
|
||||
public static final String CHANNEL_NONSYNC = "nonsync";
|
||||
public static final String CHANNEL_MIC = "mic";
|
||||
|
||||
// List of properties
|
||||
public static final String PROPERTY_VERSION = "osVersion";
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2024 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.dolbycp.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
/**
|
||||
* The {@link DolbyCPConfiguration} class contains fields mapping thing configuration parameters.
|
||||
*
|
||||
* @author Roland Tapken - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DolbyCPConfiguration {
|
||||
/**
|
||||
* Hostname or IP address of the CP750 device
|
||||
*/
|
||||
public String hostname = "";
|
||||
|
||||
/**
|
||||
* TCP Port to connect to (default: 61408)
|
||||
*/
|
||||
public int port = 61408;
|
||||
|
||||
/**
|
||||
* Interval in seconds to update channels
|
||||
*/
|
||||
public int refreshInterval = 5;
|
||||
|
||||
/**
|
||||
* Reconnect interval in seconds after a broken TCP connection
|
||||
*/
|
||||
public int reconnectInterval = 10;
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2024 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.dolbycp.internal;
|
||||
|
||||
import static org.openhab.binding.dolbycp.internal.DolbyCPBindingConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.IncreaseDecreaseType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
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;
|
||||
|
||||
import de.cybso.cp750.CP750Client;
|
||||
import de.cybso.cp750.CP750Field;
|
||||
import de.cybso.cp750.CP750InputMode;
|
||||
import de.cybso.cp750.CP750Listener;
|
||||
|
||||
/**
|
||||
* The {@link DolbyCPHandler} is responsible for handling commands, which are
|
||||
* sent to one of the channels.
|
||||
*
|
||||
* @author Roland Tapken - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class DolbyCPHandler extends BaseThingHandler implements CP750Listener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(DolbyCPHandler.class);
|
||||
|
||||
private @Nullable DolbyCPConfiguration config;
|
||||
|
||||
private @Nullable CP750Client client;
|
||||
|
||||
private @Nullable ScheduledFuture<?> scheduleFuture;
|
||||
|
||||
private @Nullable CP750InputMode currentInputMode;
|
||||
|
||||
public DolbyCPHandler(Thing thing) {
|
||||
super(thing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||
CP750Client client = this.client;
|
||||
if (client != null) {
|
||||
try {
|
||||
if (command instanceof RefreshType) {
|
||||
client.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (channelUID.getId()) {
|
||||
case CHANNEL_INPUT -> {
|
||||
if (command instanceof StringType commandAsStringType) {
|
||||
CP750InputMode mode = CP750InputMode.byValue(commandAsStringType.toString());
|
||||
if (mode != null) {
|
||||
client.setInputMode(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
case CHANNEL_ANALOG -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.ANALOG);
|
||||
} else if (currentInputMode == CP750InputMode.ANALOG) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_DIG1 -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.DIG_1);
|
||||
} else if (currentInputMode == CP750InputMode.DIG_1) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_DIG2 -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.DIG_2);
|
||||
} else if (currentInputMode == CP750InputMode.DIG_2) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_DIG3 -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.DIG_3);
|
||||
} else if (currentInputMode == CP750InputMode.DIG_3) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_DIG4 -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.DIG_4);
|
||||
} else if (currentInputMode == CP750InputMode.DIG_4) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_MIC -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.MIC);
|
||||
} else if (currentInputMode == CP750InputMode.MIC) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_NONSYNC -> {
|
||||
if (command == OnOffType.ON) {
|
||||
client.setInputMode(CP750InputMode.NON_SYNC);
|
||||
} else if (currentInputMode == CP750InputMode.NON_SYNC) {
|
||||
client.setInputMode(CP750InputMode.LAST);
|
||||
}
|
||||
}
|
||||
case CHANNEL_MUTE -> {
|
||||
if (command instanceof OnOffType) {
|
||||
client.setMuted(command == OnOffType.ON);
|
||||
}
|
||||
}
|
||||
case CHANNEL_FADER -> {
|
||||
if (command instanceof DecimalType commandAsDecimalType) {
|
||||
client.setFader(commandAsDecimalType.intValue());
|
||||
}
|
||||
if (command instanceof IncreaseDecreaseType) {
|
||||
client.setFaderDelta(command == IncreaseDecreaseType.INCREASE ? 1 : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
releaseAndReconnect(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
final DolbyCPConfiguration config = getConfigAs(DolbyCPConfiguration.class);
|
||||
this.config = config;
|
||||
updateStatus(ThingStatus.UNKNOWN);
|
||||
|
||||
scheduler.execute(() -> {
|
||||
try {
|
||||
CP750Client client = new CP750Client(config.hostname, config.port);
|
||||
this.client = client;
|
||||
for (CP750Field field : CP750Field.values()) {
|
||||
if (field == CP750Field.SYSINFO_VERSION) {
|
||||
// This needs to be only updated once
|
||||
client.addOnetimeListener(field, this);
|
||||
} else {
|
||||
client.addListener(field, this);
|
||||
}
|
||||
}
|
||||
updateStatus(ThingStatus.ONLINE);
|
||||
|
||||
// Schedule first refresh by now and more after configured refresh interval
|
||||
this.scheduleFuture = scheduler.scheduleWithFixedDelay(this::refresh, 100, config.refreshInterval,
|
||||
TimeUnit.SECONDS);
|
||||
} catch (IOException e) {
|
||||
releaseAndReconnect(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel scheduled futures and close the client connection.
|
||||
* Will not update status, this has to be done by the invoking method.
|
||||
*/
|
||||
private void releaseResources() {
|
||||
ScheduledFuture<?> scheduleFuture = this.scheduleFuture;
|
||||
this.scheduleFuture = null;
|
||||
if (scheduleFuture != null) {
|
||||
scheduleFuture.cancel(true);
|
||||
}
|
||||
CP750Client client = this.client;
|
||||
this.client = null;
|
||||
if (client != null) {
|
||||
client.removeListener(this);
|
||||
try {
|
||||
client.close();
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release resources and, if greater 0, tries to reconnect
|
||||
* after configured time in seconds.
|
||||
*/
|
||||
private void releaseAndReconnect(@Nullable String errorMessage) {
|
||||
releaseResources();
|
||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, errorMessage);
|
||||
DolbyCPConfiguration config = this.config;
|
||||
if (config != null && config.reconnectInterval > 0) {
|
||||
logger.debug("DolbyCP at {}:{} try to reconnect in {} seconds", config.hostname, config.port,
|
||||
config.reconnectInterval);
|
||||
scheduler.schedule(() -> {
|
||||
if (getThing().getStatus() == ThingStatus.OFFLINE) {
|
||||
// Will call disposeAndReconnect() if something goes wrong
|
||||
initialize();
|
||||
}
|
||||
}, config.reconnectInterval, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
releaseResources();
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
try {
|
||||
CP750Client client = this.client;
|
||||
if (client != null) {
|
||||
client.refresh();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
releaseAndReconnect(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles input data
|
||||
*/
|
||||
@Override
|
||||
public void receive(@Nullable CP750Field field, @Nullable String value) {
|
||||
DolbyCPConfiguration config = this.config;
|
||||
String hostname = config == null ? "unknown" : config.hostname;
|
||||
int port = config == null ? -1 : config.port;
|
||||
|
||||
logger.debug("DolbyCP at {}:{} received {} with value {}", hostname, port, field, value);
|
||||
if (field == null || value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (field) {
|
||||
case SYSINFO_VERSION -> updateProperty(PROPERTY_VERSION, value);
|
||||
case SYS_MUTE -> updateState(CHANNEL_MUTE, OnOffType.from(value));
|
||||
case SYS_FADER -> updateState(CHANNEL_FADER, PercentType.valueOf(value));
|
||||
case SYS_INPUT_MODE -> {
|
||||
CP750InputMode mode = CP750InputMode.byValue(value);
|
||||
if (mode != null) {
|
||||
this.currentInputMode = mode;
|
||||
updateState(CHANNEL_INPUT, StringType.valueOf(value));
|
||||
OnOffType analog = OnOffType.OFF;
|
||||
OnOffType dig1 = OnOffType.OFF;
|
||||
OnOffType dig2 = OnOffType.OFF;
|
||||
OnOffType dig3 = OnOffType.OFF;
|
||||
OnOffType dig4 = OnOffType.OFF;
|
||||
OnOffType nonsync = OnOffType.OFF;
|
||||
OnOffType mic = OnOffType.OFF;
|
||||
switch (mode) {
|
||||
case ANALOG -> analog = OnOffType.ON;
|
||||
case DIG_1 -> dig1 = OnOffType.ON;
|
||||
case DIG_2 -> dig2 = OnOffType.ON;
|
||||
case DIG_3 -> dig3 = OnOffType.ON;
|
||||
case DIG_4 -> dig4 = OnOffType.ON;
|
||||
case MIC -> mic = OnOffType.ON;
|
||||
case NON_SYNC -> nonsync = OnOffType.ON;
|
||||
default -> {
|
||||
// Ignore unknown value
|
||||
}
|
||||
}
|
||||
updateState(CHANNEL_ANALOG, analog);
|
||||
updateState(CHANNEL_DIG1, dig1);
|
||||
updateState(CHANNEL_DIG2, dig2);
|
||||
updateState(CHANNEL_DIG3, dig3);
|
||||
updateState(CHANNEL_DIG4, dig4);
|
||||
updateState(CHANNEL_MIC, mic);
|
||||
updateState(CHANNEL_NONSYNC, nonsync);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
// Ignore unknown value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2024 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.dolbycp.internal;
|
||||
|
||||
import static org.openhab.binding.dolbycp.internal.DolbyCPBindingConstants.*;
|
||||
|
||||
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 DolbyCPHandlerFactory} is responsible for creating things and thing
|
||||
* handlers.
|
||||
*
|
||||
* @author Roland Tapken - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@Component(configurationPid = "binding.dolbycp", service = ThingHandlerFactory.class)
|
||||
public class DolbyCPHandlerFactory extends BaseThingHandlerFactory {
|
||||
|
||||
private static final Set<ThingTypeUID> 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 DolbyCPHandler(thing);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<addon:addon id="dolbycp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:addon="https://openhab.org/schemas/addon/v1.0.0"
|
||||
xsi:schemaLocation="https://openhab.org/schemas/addon/v1.0.0 https://openhab.org/schemas/addon-1.0.0.xsd">
|
||||
|
||||
<type>binding</type>
|
||||
<name>DolbyCP Binding</name>
|
||||
<description>This is the binding for controlling a Dolby CP750</description>
|
||||
<connection>local</connection>
|
||||
|
||||
</addon:addon>
|
@ -0,0 +1,51 @@
|
||||
# add-on
|
||||
|
||||
addon.dolbycp.name = DolbyCP Binding
|
||||
addon.dolbycp.description = This is the binding for controlling a Dolby CP750
|
||||
|
||||
# thing types
|
||||
|
||||
thing-type.dolbycp.cp750.label = CP750 Device
|
||||
thing-type.dolbycp.cp750.description = Binding for Dolby Cinema Processor CP750
|
||||
|
||||
# thing types config
|
||||
|
||||
thing-type.config.dolbycp.cp750.hostname.label = Hostname
|
||||
thing-type.config.dolbycp.cp750.hostname.description = Hostname or IP address of the device
|
||||
thing-type.config.dolbycp.cp750.port.label = Port
|
||||
thing-type.config.dolbycp.cp750.port.description = Port to access the device
|
||||
thing-type.config.dolbycp.cp750.reconnectInterval.label = Retry Interval
|
||||
thing-type.config.dolbycp.cp750.reconnectInterval.description = Reconnect interval in seconds after connection failure (0 = disabled)
|
||||
thing-type.config.dolbycp.cp750.refreshInterval.label = Refresh Interval
|
||||
thing-type.config.dolbycp.cp750.refreshInterval.description = Interval the device is polled in sec.
|
||||
|
||||
# channel types
|
||||
|
||||
channel-type.dolbycp.fader.label = Fader
|
||||
channel-type.dolbycp.fader.description = Fader state
|
||||
channel-type.dolbycp.input-analog.label = Analog Input
|
||||
channel-type.dolbycp.input-analog.description = Handles the state of INPUT_MODE=analog
|
||||
channel-type.dolbycp.input-dig1.label = Digital Input 1
|
||||
channel-type.dolbycp.input-dig1.description = Handles the state of INPUT_MODE=dig_1
|
||||
channel-type.dolbycp.input-dig2.label = Digital Input 2
|
||||
channel-type.dolbycp.input-dig2.description = Handles the state of INPUT_MODE=dig_3
|
||||
channel-type.dolbycp.input-dig3.label = Digital Input 3
|
||||
channel-type.dolbycp.input-dig3.description = Handles the state of INPUT_MODE=dig_3
|
||||
channel-type.dolbycp.input-dig4.label = Digital Input 4
|
||||
channel-type.dolbycp.input-dig4.description = Handles the state of INPUT_MODE=dig_4
|
||||
channel-type.dolbycp.input-mic.label = Mic Input
|
||||
channel-type.dolbycp.input-mic.description = Handles the state of INPUT_MODE=mic
|
||||
channel-type.dolbycp.input-non_sync.label = Non-Sync Input
|
||||
channel-type.dolbycp.input-non_sync.description = Handles the state of INPUT_MODE=non_sync
|
||||
channel-type.dolbycp.input.label = Current Input
|
||||
channel-type.dolbycp.input.description = Handles the state of INPUT_MODE
|
||||
channel-type.dolbycp.input.state.option.analog = Analog
|
||||
channel-type.dolbycp.input.state.option.dig_1 = Digital 1
|
||||
channel-type.dolbycp.input.state.option.dig_2 = Digital 2
|
||||
channel-type.dolbycp.input.state.option.dig_3 = Digital 3
|
||||
channel-type.dolbycp.input.state.option.dig_4 = Digital 4
|
||||
channel-type.dolbycp.input.state.option.non_sync = Non-Sync
|
||||
channel-type.dolbycp.input.state.option.mic = Microphone
|
||||
channel-type.dolbycp.input.state.option.last = Last active input
|
||||
channel-type.dolbycp.mute.label = Mute
|
||||
channel-type.dolbycp.mute.description = Mute state
|
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<thing:thing-descriptions bindingId="dolbycp"
|
||||
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="cp750">
|
||||
<label>CP750 Device</label>
|
||||
<description>Binding for Dolby Cinema Processor CP750</description>
|
||||
|
||||
<channels>
|
||||
<channel id="fader" typeId="fader"/>
|
||||
<channel id="mute" typeId="mute"/>
|
||||
<channel id="input" typeId="input"/>
|
||||
<channel id="analog" typeId="input-analog"/>
|
||||
<channel id="dig1" typeId="input-dig1"/>
|
||||
<channel id="dig2" typeId="input-dig2"/>
|
||||
<channel id="dig3" typeId="input-dig3"/>
|
||||
<channel id="dig4" typeId="input-dig4"/>
|
||||
<channel id="nonsync" typeId="input-non_sync"/>
|
||||
<channel id="mic" typeId="input-mic"/>
|
||||
</channels>
|
||||
|
||||
<properties>
|
||||
<property name="osVersion"></property>
|
||||
</properties>
|
||||
|
||||
<config-description>
|
||||
<parameter name="hostname" type="text" required="true">
|
||||
<context>network-address</context>
|
||||
<label>Hostname</label>
|
||||
<description>Hostname or IP address of the device</description>
|
||||
</parameter>
|
||||
<parameter name="port" type="integer" min="1" max="65535">
|
||||
<label>Port</label>
|
||||
<default>61408</default>
|
||||
<description>Port to access the device</description>
|
||||
</parameter>
|
||||
<parameter name="refreshInterval" type="integer" unit="s" min="1">
|
||||
<advanced>true</advanced>
|
||||
<label>Refresh Interval</label>
|
||||
<description>Interval the device is polled in sec.</description>
|
||||
<default>5</default>
|
||||
</parameter>
|
||||
<parameter name="reconnectInterval" type="integer" unit="s" min="0">
|
||||
<advanced>true</advanced>
|
||||
<label>Retry Interval</label>
|
||||
<description>Reconnect interval in seconds after connection failure (0 = disabled)</description>
|
||||
<default>10</default>
|
||||
</parameter>
|
||||
</config-description>
|
||||
</thing-type>
|
||||
|
||||
<!-- Sample Channel Type -->
|
||||
<channel-type id="fader">
|
||||
<item-type>Dimmer</item-type>
|
||||
<label>Fader</label>
|
||||
<description>Fader state</description>
|
||||
</channel-type>
|
||||
<channel-type id="mute">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Mute</label>
|
||||
<description>Mute state</description>
|
||||
</channel-type>
|
||||
<channel-type id="input">
|
||||
<item-type>String</item-type>
|
||||
<label>Current Input</label>
|
||||
<description>Handles the state of INPUT_MODE</description>
|
||||
<state pattern="%s">
|
||||
<options>
|
||||
<option value="analog">Analog</option>
|
||||
<option value="dig_1">Digital 1</option>
|
||||
<option value="dig_2">Digital 2</option>
|
||||
<option value="dig_3">Digital 3</option>
|
||||
<option value="dig_4">Digital 4</option>
|
||||
<option value="non_sync">Non-Sync</option>
|
||||
<option value="mic">Microphone</option>
|
||||
<option value="last">Last active input</option>
|
||||
</options>
|
||||
</state>
|
||||
</channel-type>
|
||||
<channel-type id="input-analog">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Analog Input</label>
|
||||
<description>Handles the state of INPUT_MODE=analog</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-dig1">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Digital Input 1</label>
|
||||
<description>Handles the state of INPUT_MODE=dig_1</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-dig2">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Digital Input 2</label>
|
||||
<description>Handles the state of INPUT_MODE=dig_3</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-dig3">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Digital Input 3</label>
|
||||
<description>Handles the state of INPUT_MODE=dig_3</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-dig4">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Digital Input 4</label>
|
||||
<description>Handles the state of INPUT_MODE=dig_4</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-non_sync">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Non-Sync Input</label>
|
||||
<description>Handles the state of INPUT_MODE=non_sync</description>
|
||||
</channel-type>
|
||||
<channel-type id="input-mic">
|
||||
<item-type>Switch</item-type>
|
||||
<label>Mic Input</label>
|
||||
<description>Handles the state of INPUT_MODE=mic</description>
|
||||
</channel-type>
|
||||
</thing:thing-descriptions>
|
@ -109,6 +109,7 @@
|
||||
<module>org.openhab.binding.digitalstrom</module>
|
||||
<module>org.openhab.binding.dlinksmarthome</module>
|
||||
<module>org.openhab.binding.dmx</module>
|
||||
<module>org.openhab.binding.dolbycp</module>
|
||||
<module>org.openhab.binding.dominoswiss</module>
|
||||
<module>org.openhab.binding.doorbird</module>
|
||||
<module>org.openhab.binding.draytonwiser</module>
|
||||
|
Loading…
Reference in New Issue
Block a user