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,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.hyperion-${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-hyperion" description="Hyperion Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-transport-mdns</feature>
<feature>openhab-transport-http</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.hyperion/${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.hyperion.internal;
import java.util.HashSet;
import java.util.Set;
import org.openhab.core.thing.ThingTypeUID;
/**
* The {@link HyperionBinding} class defines common constants, which are
* used across the whole binding.
*
* @author Daniel Walters - Initial contribution
*/
public class HyperionBindingConstants {
public static final String BINDING_ID = "hyperion";
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>();
// List of all Channel ids
public static final String CHANNEL_BRIGHTNESS = "brightness";
public static final String CHANNEL_COLOR = "color";
public static final String CHANNEL_CLEAR = "clear";
public static final String CHANNEL_EFFECT = "effect";
public static final String CHANNEL_BLACKBORDER = "blackborder";
public static final String CHANNEL_SMOOTHING = "smoothing";
public static final String CHANNEL_KODICHECKER = "kodichecker";
public static final String CHANNEL_FORWARDER = "forwarder";
public static final String CHANNEL_UDPLISTENER = "udplistener";
public static final String CHANNEL_BOBLIGHTSERVER = "boblightserver";
public static final String CHANNEL_GRABBER = "grabber";
public static final String CHANNEL_V4L = "v4l";
public static final String CHANNEL_LEDDEVICE = "leddevice";
public static final String CHANNEL_HYPERION_ENABLED = "hyperionenabled";
// Hyperion components
public static final String COMPONENT_BLACKBORDER = "BLACKBORDER";
public static final String COMPONENT_SMOOTHING = "SMOOTHING";
public static final String COMPONENT_KODICHECKER = "KODICHECKER";
public static final String COMPONENT_FORWARDER = "FORWARDER";
public static final String COMPONENT_UDPLISTENER = "UDPLISTENER";
public static final String COMPONENT_BOBLIGHTSERVER = "BOBLIGHTSERVER";
public static final String COMPONENT_GRABBER = "GRABBER";
public static final String COMPONENT_V4L = "V4L";
public static final String COMPONENT_LEDDEVICE = "LEDDEVICE";
public static final String COMPONENT_ALL = "ALL";
// List of all properties
public static final String PROP_HOST = "host";
public static final String PROP_PORT = "port";
public static final String PROP_PRIORITY = "priority";
public static final String PROP_POLL_FREQUENCY = "poll_frequency";
public static final String PROP_ORIGIN = "origin";
// config
public static final String HOST = "host";
public static final String PORT = "port";
// thing-types
public static final String SERVER_V1 = "serverV1";
public static final String SERVER_NG = "serverNG";
// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_SERVER_V1 = new ThingTypeUID(BINDING_ID, SERVER_V1);
public static final ThingTypeUID THING_TYPE_SERVER_NG = new ThingTypeUID(BINDING_ID, SERVER_NG);
static {
SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_SERVER_V1);
SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_SERVER_NG);
}
}

View File

@@ -0,0 +1,91 @@
/**
* 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.hyperion.internal;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.jmdns.ServiceInfo;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
/**
* The {@link HyperionDiscoveryParticipant} class is responsible for listening
* to MDNS responses and discovering Hyperion.ng servers.
*
* @author Daniel Walters - Initial contribution
*/
@Component(immediate = true)
public class HyperionDiscoveryParticipant implements MDNSDiscoveryParticipant {
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return Collections.singleton(HyperionBindingConstants.THING_TYPE_SERVER_NG);
}
@Override
public String getServiceType() {
return "_hyperiond-json._tcp.local.";
}
@Override
public DiscoveryResult createResult(ServiceInfo service) {
DiscoveryResult result = null;
// return null if the service info is invalid / not fully formed
if (service.getHostAddresses().length == 0) {
return null;
}
final Map<String, Object> properties = new HashMap<>(2);
String host = service.getHostAddresses()[0];
BigDecimal port = new BigDecimal(service.getPort());
properties.put(HyperionBindingConstants.HOST, host);
properties.put(HyperionBindingConstants.PORT, port);
String longName = service.getName();
int pos = longName.indexOf("@");
if (pos < 0 || pos >= longName.length()) {
return null;
}
String friendlyName = longName.substring(0, pos);
ThingUID uid = getThingUID(service);
if (uid != null) {
result = DiscoveryResultBuilder.create(uid).withThingType(HyperionBindingConstants.THING_TYPE_SERVER_NG)
.withProperties(properties).withLabel(friendlyName).build();
}
return result;
}
@Override
public ThingUID getThingUID(ServiceInfo service) {
String uid = service.getPropertyString("id");
if (uid == null) {
String longName = service.getName();
int hashCode = longName.hashCode();
uid = Integer.toUnsignedString(hashCode);
}
return new ThingUID(HyperionBindingConstants.THING_TYPE_SERVER_NG, uid);
}
}

View File

@@ -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.hyperion.internal;
import org.openhab.binding.hyperion.internal.handler.HyperionHandler;
import org.openhab.binding.hyperion.internal.handler.HyperionNgHandler;
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;
import org.osgi.service.component.annotations.Reference;
/**
* The {@link HyperionHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Daniel Walters - Initial contribution
*/
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.hyperion")
public class HyperionHandlerFactory extends BaseThingHandlerFactory {
private HyperionStateDescriptionProvider stateDescriptionProvider;
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return HyperionBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}
@Override
protected ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(HyperionBindingConstants.THING_TYPE_SERVER_V1)) {
return new HyperionHandler(thing);
} else if (thingTypeUID.equals(HyperionBindingConstants.THING_TYPE_SERVER_NG)) {
return new HyperionNgHandler(thing, stateDescriptionProvider);
}
return null;
}
@Reference
protected void setDynamicStateDescriptionProvider(HyperionStateDescriptionProvider stateDescriptionProvider) {
this.stateDescriptionProvider = stateDescriptionProvider;
}
protected void unsetDynamicStateDescriptionProvider(HyperionStateDescriptionProvider stateDescriptionProvider) {
this.stateDescriptionProvider = null;
}
}

View File

@@ -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.hyperion.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider;
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
import org.openhab.core.thing.type.DynamicStateDescriptionProvider;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* The {@link HyperionStateDescriptionProvider} class is a dynamic provider of state options while leaving other state
* description fields as original.
*
* @author Gregory Moyer - Initial contribution
* @author Daniel Walters - Adapted for Hyperion Binding
*/
@Component(service = { DynamicStateDescriptionProvider.class, HyperionStateDescriptionProvider.class })
@NonNullByDefault
public class HyperionStateDescriptionProvider extends BaseDynamicStateDescriptionProvider {
@Reference
protected void setChannelTypeI18nLocalizationService(
final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
}
protected void unsetChannelTypeI18nLocalizationService(
final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
this.channelTypeI18nLocalizationService = null;
}
}

View File

@@ -0,0 +1,93 @@
/**
* 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.hyperion.internal.connection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link JsonTcpConnection} class is responsible for handling
* the communication with the Hyperion json server.
*
* @author Daniel Walters - Initial contribution
*/
public class JsonTcpConnection {
private final Logger logger = LoggerFactory.getLogger(JsonTcpConnection.class);
private InetAddress address;
private int port;
private Socket hyperionServerSocket;
public JsonTcpConnection(InetAddress address, int port) {
this.setAddress(address);
this.port = port;
}
public JsonTcpConnection(String sAddress, int port) throws UnknownHostException {
this(InetAddress.getByName(sAddress), port);
}
public int getPort() {
return port;
}
public InetAddress getAddress() {
return address;
}
public void setAddress(InetAddress address) {
this.address = address;
}
public String send(String json) throws IOException {
String response = null;
try (Socket hyperionServer = new Socket(address, port);
DataOutputStream outToServer = new DataOutputStream(hyperionServer.getOutputStream());
Reader isr = new InputStreamReader(hyperionServer.getInputStream());
BufferedReader inFromServer = new BufferedReader(isr)) {
logger.debug("Sending: {}", json);
outToServer.writeBytes(json + System.lineSeparator());
outToServer.flush();
response = inFromServer.readLine();
} catch (IOException e) {
throw e;
}
logger.debug("Received: {}", response);
return response;
}
public void connect() throws IOException {
if (hyperionServerSocket == null || !hyperionServerSocket.isConnected()) {
hyperionServerSocket = new Socket(address, port);
}
}
public void close() throws IOException {
if (hyperionServerSocket != null && hyperionServerSocket.isConnected()) {
hyperionServerSocket.close();
}
}
public boolean isConnected() {
return hyperionServerSocket != null && hyperionServerSocket.isConnected();
}
}

View File

@@ -0,0 +1,315 @@
/**
* 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.hyperion.internal.handler;
import static org.openhab.binding.hyperion.internal.HyperionBindingConstants.*;
import java.awt.Color;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.openhab.binding.hyperion.internal.connection.JsonTcpConnection;
import org.openhab.binding.hyperion.internal.protocol.ColorCommand;
import org.openhab.binding.hyperion.internal.protocol.CommandUnsuccessfulException;
import org.openhab.binding.hyperion.internal.protocol.EffectCommand;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
import org.openhab.binding.hyperion.internal.protocol.ServerInfoCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.ActiveEffect;
import org.openhab.binding.hyperion.internal.protocol.v1.ActiveLedColor;
import org.openhab.binding.hyperion.internal.protocol.v1.ClearAllCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.ClearCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.Effect;
import org.openhab.binding.hyperion.internal.protocol.v1.Transform;
import org.openhab.binding.hyperion.internal.protocol.v1.TransformCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.V1Info;
import org.openhab.binding.hyperion.internal.protocol.v1.V1Response;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.HSBType;
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.openhab.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
/**
* The {@link HyperionHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Daniel Walters - Initial contribution
*/
public class HyperionHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(HyperionHandler.class);
private JsonTcpConnection connection;
private ScheduledFuture<?> refreshFuture;
private ScheduledFuture<?> connectFuture;
private Gson gson = new Gson();
private static final ServerInfoCommand SERVER_INFO_COMMAND = new ServerInfoCommand();
private String address;
private int port;
private int refreshInterval;
private int priority;
private Runnable refreshJob = new Runnable() {
@Override
public void run() {
try {
V1Response response = sendCommand(SERVER_INFO_COMMAND);
if (response.isSuccess()) {
handleServerInfoResponse(response);
}
} catch (IOException e) {
logger.debug("Could not connect to server.");
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (JsonParseException e) {
logger.debug("{}", e.getMessage(), e);
} catch (CommandUnsuccessfulException e) {
logger.debug("Server rejected the command: {}", e.getMessage());
}
}
};
private Runnable connectionJob = new Runnable() {
@Override
public void run() {
try {
if (!connection.isConnected()) {
connection.connect();
updateOnlineStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
}
} catch (IOException e) {
logger.debug("Could not connect to server.");
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
};
public HyperionHandler(Thing thing) {
super(thing);
}
protected void handleServerInfoResponse(V1Response response) {
V1Info info = response.getInfo();
if (info != null) {
// update Color
List<ActiveLedColor> activeColors = info.getActiveLedColor();
updateColor(activeColors);
// update effect
List<ActiveEffect> activeEffects = info.getActiveEffects();
List<Effect> effects = info.getEffects();
updateEffect(activeEffects, effects);
// update transform
List<Transform> transform = info.getTransform();
updateTransform(transform);
}
}
private void updateTransform(List<Transform> transform) {
Optional<Transform> defaultTransform = transform.stream() // convert list to stream
.findFirst();
if (defaultTransform.isPresent()) {
double luminanceGain = defaultTransform.get().getLuminanceGain();
if (luminanceGain >= 0.0 && luminanceGain <= 1.0) {
PercentType luminanceGainPercentType = new PercentType((int) (luminanceGain * 100));
updateState(CHANNEL_BRIGHTNESS, luminanceGainPercentType);
}
} else {
updateState(CHANNEL_BRIGHTNESS, UnDefType.NULL);
}
}
private void updateEffect(List<ActiveEffect> activeEffects, List<Effect> effects) {
Optional<ActiveEffect> effect = activeEffects.stream() // convert list to stream
.findFirst();
if (effect.isPresent()) {
String path = effect.get().getScript();
Optional<Effect> effectDescription = effects.stream() // convert list to stream
.filter(effectCandidate -> effectCandidate.getScript().equals(path)).findFirst();
if (effectDescription.isPresent()) {
String effectName = effectDescription.get().getName();
updateState(CHANNEL_EFFECT, new StringType(effectName));
}
} else {
updateState(CHANNEL_EFFECT, UnDefType.NULL);
}
}
private void updateColor(List<ActiveLedColor> activeColors) {
Optional<ActiveLedColor> color = activeColors.stream() // convert list to stream
.findFirst();
if (color.isPresent()) {
List<Integer> rgbVals = color.get().getRGBValue();
int r = rgbVals.get(0);
int g = rgbVals.get(1);
int b = rgbVals.get(2);
HSBType hsbType = HSBType.fromRGB(r, g, b);
updateState(CHANNEL_COLOR, hsbType);
} else {
updateState(CHANNEL_COLOR, UnDefType.NULL);
}
}
@Override
public void initialize() {
logger.debug("Initializing Hyperion thing handler.");
try {
Configuration config = thing.getConfiguration();
address = (String) config.get(PROP_HOST);
port = ((BigDecimal) config.get(PROP_PORT)).intValue();
refreshInterval = ((BigDecimal) config.get(PROP_POLL_FREQUENCY)).intValue();
priority = ((BigDecimal) config.get(PROP_PRIORITY)).intValue();
connection = new JsonTcpConnection(address, port);
connectFuture = scheduler.scheduleWithFixedDelay(connectionJob, 0, refreshInterval, TimeUnit.SECONDS);
refreshFuture = scheduler.scheduleWithFixedDelay(refreshJob, 0, refreshInterval, TimeUnit.SECONDS);
} catch (UnknownHostException e) {
logger.debug("Could not resolve host: {}", e.getMessage());
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
@Override
public void dispose() {
logger.debug("Disposing of Hyperion thing handler.");
if (refreshFuture != null) {
refreshFuture.cancel(true);
}
if (connectFuture != null) {
connectFuture.cancel(true);
}
if (connection != null && connection.isConnected()) {
try {
connection.close();
} catch (IOException e) {
// do nothing
}
}
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
try {
if (command instanceof RefreshType) {
if (refreshFuture.isDone()) {
refreshFuture = scheduler.scheduleWithFixedDelay(refreshJob, 0, refreshInterval, TimeUnit.SECONDS);
} else {
logger.debug("Previous refresh not yet completed");
}
} else if (CHANNEL_BRIGHTNESS.equals(channelUID.getId())) {
handleBrightness(command);
} else if (CHANNEL_COLOR.equals(channelUID.getId())) {
handleColor(command);
} else if (CHANNEL_CLEAR.equals(channelUID.getId())) {
handleClear(command);
} else if (CHANNEL_EFFECT.equals(channelUID.getId())) {
handleEffect(command);
}
} catch (IOException e) {
logger.debug("Unable to send command: {}", command);
} catch (CommandUnsuccessfulException e) {
logger.debug("Server rejected the command: {}", e.getMessage());
}
}
private void handleEffect(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof StringType) {
String effectName = command.toString();
Effect effect = new Effect(effectName);
EffectCommand effectCommand = new EffectCommand(effect, priority);
sendCommand(effectCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_EFFECT, command);
}
}
private void handleBrightness(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof PercentType) {
PercentType percent = (PercentType) command;
Transform transform = new Transform();
transform.setLuminanceGain(percent.doubleValue() / 100);
TransformCommand transformCommand = new TransformCommand(transform);
sendCommand(transformCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_BRIGHTNESS, command);
}
}
private void handleColor(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof HSBType) {
HSBType color = (HSBType) command;
Color c = new Color(color.getRGB());
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
ColorCommand colorCommand = new ColorCommand(r, g, b, priority);
sendCommand(colorCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_COLOR, command);
}
}
private void handleClear(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof StringType) {
String cmd = command.toString();
if ("ALL".equals(cmd)) {
ClearAllCommand clearCommand = new ClearAllCommand();
sendCommand(clearCommand);
} else {
int priority = Integer.parseInt(cmd);
ClearCommand clearCommand = new ClearCommand(priority);
sendCommand(clearCommand);
}
}
}
public V1Response sendCommand(HyperionCommand command) throws IOException, CommandUnsuccessfulException {
String commandJson = gson.toJson(command);
String jsonResponse = connection.send(commandJson);
V1Response response = gson.fromJson(jsonResponse, V1Response.class);
if (!response.isSuccess()) {
throw new CommandUnsuccessfulException(gson.toJson(command));
}
return response;
}
private void updateOnlineStatus(ThingStatus status, ThingStatusDetail detail, String message) {
ThingStatus current = thing.getStatus();
ThingStatusDetail currentDetail = thing.getStatusInfo().getStatusDetail();
if (!current.equals(status) || !currentDetail.equals(detail)) {
updateStatus(status, detail, message);
}
}
}

View File

@@ -0,0 +1,502 @@
/**
* 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.hyperion.internal.handler;
import static org.openhab.binding.hyperion.internal.HyperionBindingConstants.*;
import java.awt.Color;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.openhab.binding.hyperion.internal.HyperionStateDescriptionProvider;
import org.openhab.binding.hyperion.internal.connection.JsonTcpConnection;
import org.openhab.binding.hyperion.internal.protocol.ColorCommand;
import org.openhab.binding.hyperion.internal.protocol.CommandUnsuccessfulException;
import org.openhab.binding.hyperion.internal.protocol.EffectCommand;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
import org.openhab.binding.hyperion.internal.protocol.ServerInfoCommand;
import org.openhab.binding.hyperion.internal.protocol.ng.Adjustment;
import org.openhab.binding.hyperion.internal.protocol.ng.AdjustmentCommand;
import org.openhab.binding.hyperion.internal.protocol.ng.Component;
import org.openhab.binding.hyperion.internal.protocol.ng.ComponentState;
import org.openhab.binding.hyperion.internal.protocol.ng.ComponentStateCommand;
import org.openhab.binding.hyperion.internal.protocol.ng.Hyperion;
import org.openhab.binding.hyperion.internal.protocol.ng.NgInfo;
import org.openhab.binding.hyperion.internal.protocol.ng.NgResponse;
import org.openhab.binding.hyperion.internal.protocol.ng.Priority;
import org.openhab.binding.hyperion.internal.protocol.ng.Value;
import org.openhab.binding.hyperion.internal.protocol.v1.ClearAllCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.ClearCommand;
import org.openhab.binding.hyperion.internal.protocol.v1.Effect;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.HSBType;
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.ThingStatusInfo;
import org.openhab.core.thing.binding.BaseThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.StateOption;
import org.openhab.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
/**
* The {@link HyperionNgHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Daniel Walters - Initial contribution
*/
public class HyperionNgHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(HyperionNgHandler.class);
private static final String COLOR_PRIORITY = "COLOR";
private static final String EFFECT_PRIORITY = "EFFECT";
private static final String DEFAULT_ADJUSTMENT = "default";
private static final String COMPONENTS_ALL = "ALL";
private JsonTcpConnection connection;
private ScheduledFuture<?> refreshFuture;
private ScheduledFuture<?> connectFuture;
private Gson gson = new Gson();
private static final ServerInfoCommand SERVER_INFO_COMMAND = new ServerInfoCommand();
private String address;
private int port;
private int refreshInterval;
private int priority;
private String origin;
private HyperionStateDescriptionProvider stateDescriptionProvider;
private Runnable refreshJob = new Runnable() {
@Override
public void run() {
try {
NgResponse response = sendCommand(SERVER_INFO_COMMAND);
if (response.isSuccess()) {
handleServerInfoResponse(response);
}
updateOnlineStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
} catch (IOException e) {
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (JsonParseException e) {
logger.debug("{}", e.getMessage(), e);
} catch (CommandUnsuccessfulException e) {
logger.debug("Server rejected the command: {}", e.getMessage());
}
}
};
private Runnable connectionJob = new Runnable() {
@Override
public void run() {
try {
if (!connection.isConnected()) {
connection.connect();
updateOnlineStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
}
} catch (IOException e) {
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
};
public HyperionNgHandler(Thing thing, HyperionStateDescriptionProvider stateDescriptionProvider) {
super(thing);
this.stateDescriptionProvider = stateDescriptionProvider;
}
@Override
public void initialize() {
logger.debug("Initializing Hyperion.ng thing handler.");
try {
Configuration config = thing.getConfiguration();
address = (String) config.get(PROP_HOST);
port = ((BigDecimal) config.get(PROP_PORT)).intValue();
refreshInterval = ((BigDecimal) config.get(PROP_POLL_FREQUENCY)).intValue();
priority = ((BigDecimal) config.get(PROP_PRIORITY)).intValue();
origin = (String) config.get(PROP_ORIGIN);
connection = new JsonTcpConnection(address, port);
connectFuture = scheduler.scheduleWithFixedDelay(connectionJob, 0, refreshInterval, TimeUnit.SECONDS);
refreshFuture = scheduler.scheduleWithFixedDelay(refreshJob, 0, refreshInterval, TimeUnit.SECONDS);
} catch (UnknownHostException e) {
logger.debug("Could not resolve host: {}", e.getMessage());
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
@Override
public void dispose() {
logger.debug("Disposing of Hyperion.ng thing handler.");
if (refreshFuture != null) {
refreshFuture.cancel(true);
}
if (connectFuture != null) {
connectFuture.cancel(true);
}
if (connection != null && connection.isConnected()) {
try {
connection.close();
} catch (IOException e) {
// do nothing
}
}
}
protected void handleServerInfoResponse(NgResponse response) {
NgInfo info = response.getInfo();
if (info != null) {
// update Hyperion, older API compatibility
Hyperion hyperion = info.getHyperion();
if (hyperion != null) {
updateHyperion(hyperion);
}
// populate the effect states
List<Effect> effects = info.getEffects();
populateEffects(effects);
// update adjustments
List<Adjustment> adjustments = info.getAdjustment();
updateAdjustments(adjustments);
// update components
List<Component> components = info.getComponents();
updateComponents(components);
// update colors/effects
List<Priority> priorities = info.getPriorities();
updatePriorities(priorities);
}
}
private void populateEffects(List<Effect> effects) {
List<StateOption> options = new ArrayList<>();
for (Effect effect : effects) {
options.add(new StateOption(effect.getName(), effect.getName()));
}
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_EFFECT), options);
}
private void updatePriorities(List<Priority> priorities) {
populateClearPriorities(priorities);
String regex = origin + ".*";
// update color
// find the color priority that has the same origin specified in the Thing configuration
Optional<Priority> colorPriority = priorities.stream() // convert list to stream
.filter(priority -> COLOR_PRIORITY.equals(priority.getComponentId())
&& priority.getOrigin().matches(regex))
.findFirst();
// if there is no color priority for the openHAB origin then set channel to NULL
if (colorPriority.isPresent()) {
Value value = colorPriority.get().getValue();
List<Integer> rgbVals = value.getRGB();
int r = rgbVals.get(0);
int g = rgbVals.get(1);
int b = rgbVals.get(2);
HSBType hsbType = HSBType.fromRGB(r, g, b);
updateState(CHANNEL_COLOR, hsbType);
} else {
updateState(CHANNEL_COLOR, UnDefType.NULL);
}
// update effect
// find the color priority that has the same origin specified in the Thing configuration
Optional<Priority> effectPriority = priorities.stream() // convert list to stream
.filter(priority -> EFFECT_PRIORITY.equals(priority.getComponentId())
&& priority.getOrigin().matches(regex))
.findFirst();
// if there is no effect priority for the openHAB origin then set channel to NULL
if (effectPriority.isPresent()) {
String effectString = effectPriority.get().getOwner();
StringType effect = new StringType(effectString);
updateState(CHANNEL_EFFECT, effect);
} else {
updateState(CHANNEL_EFFECT, UnDefType.NULL);
}
}
private void populateClearPriorities(List<Priority> priorities) {
List<StateOption> options = new ArrayList<>();
options.add(new StateOption("ALL", "ALL"));
priorities.stream()
.filter(priority -> priority.getPriority() >= 1 && priority.getPriority() <= 253 && priority.isActive())
.forEach(priority -> {
options.add(new StateOption(priority.getPriority().toString(), priority.getPriority().toString()));
});
stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_CLEAR), options);
}
private void updateHyperion(Hyperion hyperion) {
boolean isOff = hyperion.isOff();
OnOffType hyperionState = isOff ? OnOffType.OFF : OnOffType.ON;
updateState(CHANNEL_HYPERION_ENABLED, hyperionState);
}
private void updateComponents(List<Component> components) {
for (Component component : components) {
String componentName = component.getName();
boolean componentIsEnabled = component.isEnabled();
OnOffType componentState = componentIsEnabled ? OnOffType.ON : OnOffType.OFF;
switch (componentName) {
case COMPONENT_BLACKBORDER:
updateState(CHANNEL_BLACKBORDER, componentState);
break;
case COMPONENT_SMOOTHING:
updateState(CHANNEL_SMOOTHING, componentState);
break;
case COMPONENT_KODICHECKER:
updateState(CHANNEL_KODICHECKER, componentState);
break;
case COMPONENT_FORWARDER:
updateState(CHANNEL_FORWARDER, componentState);
break;
case COMPONENT_UDPLISTENER:
updateState(CHANNEL_UDPLISTENER, componentState);
break;
case COMPONENT_BOBLIGHTSERVER:
updateState(CHANNEL_BOBLIGHTSERVER, componentState);
break;
case COMPONENT_GRABBER:
updateState(CHANNEL_GRABBER, componentState);
break;
case COMPONENT_V4L:
updateState(CHANNEL_V4L, componentState);
break;
case COMPONENT_LEDDEVICE:
updateState(CHANNEL_LEDDEVICE, componentState);
break;
case COMPONENT_ALL:
updateState(CHANNEL_HYPERION_ENABLED, componentState);
break;
default:
logger.debug("Unknown component: {}", componentName);
}
}
}
private void updateAdjustments(List<Adjustment> adjustments) {
Optional<Adjustment> defaultAdjustment = adjustments.stream() // convert list to stream
.filter(adjustment -> DEFAULT_ADJUSTMENT.equals(adjustment.getId())).findFirst();
if (defaultAdjustment.isPresent()) {
int brightness = defaultAdjustment.get().getBrightness();
PercentType brightnessState = new PercentType(brightness);
updateState(CHANNEL_BRIGHTNESS, brightnessState);
} else {
updateState(CHANNEL_BRIGHTNESS, UnDefType.NULL);
}
}
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
try {
if (command instanceof RefreshType) {
if (refreshFuture.isDone()) {
refreshFuture = scheduler.scheduleWithFixedDelay(refreshJob, 0, refreshInterval, TimeUnit.SECONDS);
} else {
logger.debug("Previous refresh not yet completed");
}
} else if (CHANNEL_BRIGHTNESS.equals(channelUID.getId())) {
handleBrightness(command);
} else if (CHANNEL_COLOR.equals(channelUID.getId())) {
handleColor(command);
} else if (CHANNEL_HYPERION_ENABLED.equals(channelUID.getId())) {
handleHyperionEnabled(command);
} else if (CHANNEL_EFFECT.equals(channelUID.getId())) {
handleEffect(command);
} else if (CHANNEL_CLEAR.equals(channelUID.getId())) {
handleClear(command);
} else if (CHANNEL_BLACKBORDER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_SMOOTHING.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_KODICHECKER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_FORWARDER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_UDPLISTENER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_GRABBER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_BOBLIGHTSERVER.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_V4L.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
} else if (CHANNEL_LEDDEVICE.equals(channelUID.getId())) {
handleComponentEnabled(channelUID.getId(), command);
}
} catch (IOException e) {
updateOnlineStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} catch (CommandUnsuccessfulException e) {
logger.debug("Server rejected the command: {}", e.getMessage());
}
}
private void handleComponentEnabled(String channel, Command command)
throws IOException, CommandUnsuccessfulException {
if (command instanceof OnOffType) {
ComponentState componentState = new ComponentState();
switch (channel) {
case CHANNEL_BLACKBORDER:
componentState.setComponent(COMPONENT_BLACKBORDER);
break;
case CHANNEL_SMOOTHING:
componentState.setComponent(COMPONENT_SMOOTHING);
break;
case CHANNEL_KODICHECKER:
componentState.setComponent(COMPONENT_KODICHECKER);
break;
case CHANNEL_FORWARDER:
componentState.setComponent(COMPONENT_FORWARDER);
break;
case CHANNEL_UDPLISTENER:
componentState.setComponent(COMPONENT_UDPLISTENER);
break;
case CHANNEL_BOBLIGHTSERVER:
componentState.setComponent(COMPONENT_BOBLIGHTSERVER);
break;
case CHANNEL_GRABBER:
componentState.setComponent(COMPONENT_GRABBER);
break;
case CHANNEL_V4L:
componentState.setComponent(COMPONENT_V4L);
break;
case CHANNEL_LEDDEVICE:
componentState.setComponent(COMPONENT_LEDDEVICE);
break;
}
boolean state = command == OnOffType.ON ? true : false;
componentState.setState(state);
ComponentStateCommand stateCommand = new ComponentStateCommand(componentState);
sendCommand(stateCommand);
} else {
logger.debug("Channel {} unable to process command {}", channel, command);
}
}
private void handleHyperionEnabled(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof OnOffType) {
ComponentState componentState = new ComponentState();
componentState.setComponent(COMPONENTS_ALL);
boolean state = command == OnOffType.ON ? true : false;
componentState.setState(state);
ComponentStateCommand stateCommand = new ComponentStateCommand(componentState);
sendCommand(stateCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_HYPERION_ENABLED, command);
}
}
private void handleBrightness(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof PercentType) {
PercentType percent = (PercentType) command;
int brightnessValue = percent.intValue();
Adjustment adjustment = new Adjustment();
adjustment.setBrightness(brightnessValue);
AdjustmentCommand brightnessCommand = new AdjustmentCommand(adjustment);
sendCommand(brightnessCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_BRIGHTNESS, command);
}
}
private void handleColor(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof HSBType) {
HSBType color = (HSBType) command;
Color c = new Color(color.getRGB());
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
ColorCommand colorCommand = new ColorCommand(r, g, b, priority);
colorCommand.setOrigin(origin);
sendCommand(colorCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_COLOR, command);
}
}
private void handleEffect(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof StringType) {
String effectName = command.toString();
Effect effect = new Effect(effectName);
EffectCommand effectCommand = new EffectCommand(effect, priority);
effectCommand.setOrigin(origin);
sendCommand(effectCommand);
} else {
logger.debug("Channel {} unable to process command {}", CHANNEL_EFFECT, command);
}
}
private void handleClear(Command command) throws IOException, CommandUnsuccessfulException {
if (command instanceof StringType) {
String cmd = command.toString();
if ("ALL".equals(cmd)) {
ClearAllCommand clearCommand = new ClearAllCommand();
sendCommand(clearCommand);
} else {
int priority = Integer.parseInt(cmd);
ClearCommand clearCommand = new ClearCommand(priority);
sendCommand(clearCommand);
}
}
}
private void updateOnlineStatus(ThingStatus status, ThingStatusDetail detail, String message) {
ThingStatusInfo currentStatusInfo = thing.getStatusInfo();
ThingStatus currentStatus = currentStatusInfo.getStatus();
ThingStatusDetail currentDetail = currentStatusInfo.getStatusDetail();
if (!currentStatus.equals(status) || !currentDetail.equals(detail)) {
updateStatus(status, detail, message);
}
}
public NgResponse sendCommand(HyperionCommand command) throws IOException, CommandUnsuccessfulException {
String commandJson = gson.toJson(command);
String jsonResponse = connection.send(commandJson);
NgResponse response = gson.fromJson(jsonResponse, NgResponse.class);
if (!response.isSuccess()) {
throw new CommandUnsuccessfulException(gson.toJson(command) + " - Reason: " + response.getError());
}
return response;
}
}

View File

@@ -0,0 +1,66 @@
/**
* 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.hyperion.internal.protocol;
import com.google.gson.annotations.SerializedName;
/**
* The {@link ColorCommand} is a POJO for sending a color command
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ColorCommand extends HyperionCommand {
@SerializedName("origin")
private String origin;
private static final String NAME = "color";
@SerializedName("priority")
private int priority;
@SerializedName("color")
private int[] color = new int[3];
public ColorCommand(int red, int green, int blue, int priority) {
super(NAME);
setPriority(priority);
setColor(red, green, blue);
}
public void setColor(int red, int green, int blue) {
color[0] = red;
color[1] = green;
color[2] = blue;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public int[] getColor() {
return color;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getOrigin() {
return origin;
}
}

View File

@@ -0,0 +1,28 @@
/**
* 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.hyperion.internal.protocol;
/**
* The {@link CommandUnsuccessfulException} should be raised when the Hyperion server
* rejects a command.
*
* @author Daniel Walters - Initial contribution
*/
public class CommandUnsuccessfulException extends Exception {
private static final long serialVersionUID = 1421923610566223857L;
public CommandUnsuccessfulException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,67 @@
/**
* 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.hyperion.internal.protocol;
import org.openhab.binding.hyperion.internal.protocol.v1.Effect;
import com.google.gson.annotations.SerializedName;
/**
* The {@link EffectCommand} is a POJO for sending an effect command
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class EffectCommand extends HyperionCommand {
private static final String NAME = "effect";
@SerializedName("origin")
private String origin;
@SerializedName("effect")
private Effect effect;
@SerializedName("priority")
private int priority;
public EffectCommand(Effect effect, int priority) {
super(NAME);
setEffect(effect);
setPriority(priority);
}
public Effect getEffect() {
return effect;
}
public void setEffect(Effect effect) {
this.effect = effect;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getOrigin() {
return origin;
}
}

View File

@@ -0,0 +1,39 @@
/**
* 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.hyperion.internal.protocol;
import com.google.gson.annotations.SerializedName;
/**
* The {@link HyperionCommand} is a abstract class for sending commands
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public abstract class HyperionCommand {
@SerializedName("command")
private String command;
public HyperionCommand(String command) {
setCommand(command);
}
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
}

View File

@@ -0,0 +1,28 @@
/**
* 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.hyperion.internal.protocol;
/**
* The {@link ServerInfoCommand} is a POJO for server info commands
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ServerInfoCommand extends HyperionCommand {
private static final String NAME = "serverinfo";
public ServerInfoCommand() {
super(NAME);
}
}

View File

@@ -0,0 +1,203 @@
/**
* 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.hyperion.internal.protocol.ng;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Adjustment} is a POJO for an adjustment on the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Adjustment {
@SerializedName("backlightColored")
private Boolean backlightColored;
@SerializedName("backlightThreshold")
private Integer backlightThreshold;
@SerializedName("black")
private List<Integer> black = null;
@SerializedName("blue")
private List<Integer> blue = null;
@SerializedName("brightness")
private Integer brightness;
@SerializedName("brightnessCompensation")
private Integer brightnessCompensation;
@SerializedName("cyan")
private List<Integer> cyan = null;
@SerializedName("gammaBlue")
@Expose
private Double gammaBlue;
@SerializedName("gammaGreen")
private Double gammaGreen;
@SerializedName("gammaRed")
private Double gammaRed;
@SerializedName("green")
private List<Integer> green = null;
@SerializedName("id")
private String id;
@SerializedName("magenta")
private List<Integer> magenta = null;
@SerializedName("red")
private List<Integer> red = null;
@SerializedName("white")
private List<Integer> white = null;
@SerializedName("yellow")
private List<Integer> yellow = null;
public Boolean getBacklightColored() {
return backlightColored;
}
public void setBacklightColored(Boolean backlightColored) {
this.backlightColored = backlightColored;
}
public Integer getBacklightThreshold() {
return backlightThreshold;
}
public void setBacklightThreshold(Integer backlightThreshold) {
this.backlightThreshold = backlightThreshold;
}
public List<Integer> getBlack() {
return black;
}
public void setBlack(List<Integer> black) {
this.black = black;
}
public List<Integer> getBlue() {
return blue;
}
public void setBlue(List<Integer> blue) {
this.blue = blue;
}
public Integer getBrightness() {
return brightness;
}
public void setBrightness(Integer brightness) {
this.brightness = brightness;
}
public Integer getBrightnessCompensation() {
return brightnessCompensation;
}
public void setBrightnessCompensation(Integer brightnessCompensation) {
this.brightnessCompensation = brightnessCompensation;
}
public List<Integer> getCyan() {
return cyan;
}
public void setCyan(List<Integer> cyan) {
this.cyan = cyan;
}
public Double getGammaBlue() {
return gammaBlue;
}
public void setGammaBlue(Double gammaBlue) {
this.gammaBlue = gammaBlue;
}
public Double getGammaGreen() {
return gammaGreen;
}
public void setGammaGreen(Double gammaGreen) {
this.gammaGreen = gammaGreen;
}
public Double getGammaRed() {
return gammaRed;
}
public void setGammaRed(Double gammaRed) {
this.gammaRed = gammaRed;
}
public List<Integer> getGreen() {
return green;
}
public void setGreen(List<Integer> green) {
this.green = green;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<Integer> getMagenta() {
return magenta;
}
public void setMagenta(List<Integer> magenta) {
this.magenta = magenta;
}
public List<Integer> getRed() {
return red;
}
public void setRed(List<Integer> red) {
this.red = red;
}
public List<Integer> getWhite() {
return white;
}
public void setWhite(List<Integer> white) {
this.white = white;
}
public List<Integer> getYellow() {
return yellow;
}
public void setYellow(List<Integer> yellow) {
this.yellow = yellow;
}
}

View File

@@ -0,0 +1,40 @@
/**
* 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.hyperion.internal.protocol.ng;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
/**
* The {@link AdjustmentCommand} is a POJO for sending a Adjustment command
* to the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class AdjustmentCommand extends HyperionCommand {
private static final String NAME = "adjustment";
private Adjustment adjustment;
public AdjustmentCommand(Adjustment adjustment) {
super(NAME);
setAdjustment(adjustment);
}
public Adjustment getAdjustment() {
return adjustment;
}
public void setAdjustment(Adjustment adjustment) {
this.adjustment = adjustment;
}
}

View File

@@ -0,0 +1,45 @@
/**
* 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.hyperion.internal.protocol.ng;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Component} is a POJO for a component in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Component {
@SerializedName("name")
private String name;
@SerializedName("enabled")
private boolean enabled;
public String getName() {
return name;
}
public boolean isEnabled() {
return enabled;
}
public void setName(String name) {
this.name = name;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -0,0 +1,40 @@
/**
* 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.hyperion.internal.protocol.ng;
/**
* The {@link ComponentState} is a POJO for a component state in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class ComponentState {
private String component;
private boolean state;
public void setComponent(String component) {
this.component = component;
}
public void setState(boolean state) {
this.state = state;
}
public String getComponent() {
return component;
}
public boolean getState() {
return state;
}
}

View File

@@ -0,0 +1,44 @@
/**
* 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.hyperion.internal.protocol.ng;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
import com.google.gson.annotations.SerializedName;
/**
* The {@link ComponentStateCommand} is a POJO for sending a Component State command
* to the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class ComponentStateCommand extends HyperionCommand {
private static final String NAME = "componentstate";
@SerializedName("componentstate")
private ComponentState componentState;
public ComponentStateCommand(ComponentState componentState) {
super(NAME);
setComponentState(componentState);
}
public ComponentState getComponentState() {
return componentState;
}
public void setComponentState(ComponentState componentState) {
this.componentState = componentState;
}
}

View File

@@ -0,0 +1,69 @@
/**
* 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.hyperion.internal.protocol.ng;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Hyperion} is a POJO for a Hyperion information in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Hyperion {
@SerializedName("config_modified")
private Boolean configModified;
@SerializedName("config_writeable")
private Boolean configWriteable;
@SerializedName("off")
private boolean off;
@SerializedName("sessions")
private List<Session> sessions = null;
public Boolean getConfigModified() {
return configModified;
}
public Boolean getConfigWriteable() {
return configWriteable;
}
public boolean isOff() {
return off;
}
public List<Session> getSessions() {
return sessions;
}
public void setConfigModified(Boolean configModified) {
this.configModified = configModified;
}
public void setConfigWriteable(Boolean configWriteable) {
this.configWriteable = configWriteable;
}
public void setOff(boolean off) {
this.off = off;
}
public void setSessions(List<Session> sessions) {
this.sessions = sessions;
}
}

View File

@@ -0,0 +1,78 @@
/**
* 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.hyperion.internal.protocol.ng;
import java.util.List;
import org.openhab.binding.hyperion.internal.protocol.v1.Effect;
import com.google.gson.annotations.SerializedName;
/**
* The {@link NgInfo} is a POJO for information in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class NgInfo {
@SerializedName("components")
private List<Component> components = null;
@SerializedName("adjustment")
private List<Adjustment> adjustment = null;
@SerializedName("priorities")
private List<Priority> priorities = null;
@SerializedName("hyperion")
private Hyperion hyperion = null;
@SerializedName("effects")
private List<Effect> effects = null;
public List<Component> getComponents() {
return components;
}
public List<Adjustment> getAdjustment() {
return adjustment;
}
public List<Priority> getPriorities() {
return priorities;
}
public Hyperion getHyperion() {
return hyperion;
}
public void setComponents(List<Component> components) {
this.components = components;
}
public void setAdjustment(List<Adjustment> adjustment) {
this.adjustment = adjustment;
}
public void setPriorities(List<Priority> priorities) {
this.priorities = priorities;
}
public void setHyperion(Hyperion hyperion) {
this.hyperion = hyperion;
}
public List<Effect> getEffects() {
return effects;
}
}

View File

@@ -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.hyperion.internal.protocol.ng;
import com.google.gson.annotations.SerializedName;
/**
* The {@link NgResponse} is a POJO for a response from the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class NgResponse {
@SerializedName("command")
private String command;
@SerializedName("success")
private boolean success;
@SerializedName("tan")
private int tan;
@SerializedName("info")
private NgInfo info;
@SerializedName("error")
private String error;
public String getCommand() {
return command;
}
public boolean isSuccess() {
return success;
}
public int getTan() {
return tan;
}
public NgInfo getInfo() {
return info;
}
public String getError() {
return error;
}
}

View File

@@ -0,0 +1,111 @@
/**
* 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.hyperion.internal.protocol.ng;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Priority} is a POJO for priority information in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Priority {
@SerializedName("active")
private Boolean active;
@SerializedName("componentId")
private String componentId;
@SerializedName("duration_ms")
private Integer durationMs;
@SerializedName("origin")
private String origin;
@SerializedName("owner")
private String owner;
@SerializedName("priority")
private Integer priority;
@SerializedName("visible")
private Boolean visible;
@SerializedName("value")
private Value value;
public Boolean isActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public String getComponentId() {
return componentId;
}
public void setComponentId(String componentId) {
this.componentId = componentId;
}
public Integer getDurationMs() {
return durationMs;
}
public void setDurationMs(Integer durationMs) {
this.durationMs = durationMs;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public Boolean isVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
public Value getValue() {
return value;
}
public void setValue(Value value) {
this.value = value;
}
}

View File

@@ -0,0 +1,89 @@
/**
* 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.hyperion.internal.protocol.ng;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Session} is a POJO for session information in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Session {
@SerializedName("address")
private String address;
@SerializedName("domain")
private String domain;
@SerializedName("host")
private String host;
@SerializedName("name")
private String name;
@SerializedName("port")
private Integer port;
@SerializedName("type")
private String type;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@@ -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.hyperion.internal.protocol.ng;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Value} is a POJO for value information in the Hyperion.ng server.
*
* @author Daniel Walters - Initial contribution
*/
public class Value {
@SerializedName("HEX")
private List<String> hex = null;
@SerializedName("HSL")
private List<Double> hsl = null;
@SerializedName("RGB")
private List<Integer> rgb = null;
public List<String> getHEX() {
return hex;
}
public List<Double> getHSL() {
return hsl;
}
public List<Integer> getRGB() {
return rgb;
}
public void setHEX(List<String> hex) {
this.hex = hex;
}
public void setHSL(List<Double> hsl) {
this.hsl = hsl;
}
public void setRGB(List<Integer> rgb) {
this.rgb = rgb;
}
}

View File

@@ -0,0 +1,56 @@
/**
* 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.hyperion.internal.protocol.v1;
import com.google.gson.annotations.SerializedName;
/**
* The {@link ActiveEffect} is a POJO for an active effect on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ActiveEffect {
@SerializedName("priority")
private int priority;
@SerializedName("script")
private String script;
@SerializedName("timeout")
private int timeout;
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
}

View File

@@ -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.hyperion.internal.protocol.v1;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link ActiveLedColor} is a POJO for an active LED color on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ActiveLedColor {
@SerializedName("HEX Value")
private List<String> hexValue = null;
@SerializedName("HSL Value")
private List<Double> hslValue = null;
@SerializedName("RGB Value")
private List<Integer> rgbValue = null;
public List<String> getHEXValue() {
return hexValue;
}
public void setHEXValue(List<String> hEXValue) {
this.hexValue = hEXValue;
}
public List<Double> getHSLValue() {
return hslValue;
}
public void setHSLValue(List<Double> hSLValue) {
this.hslValue = hSLValue;
}
public List<Integer> getRGBValue() {
return rgbValue;
}
public void setRGBValue(List<Integer> rGBValue) {
this.rgbValue = rGBValue;
}
}

View File

@@ -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.hyperion.internal.protocol.v1;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
/**
* The {@link ClearAllCommand} is a POJO for sending a Clear All command
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ClearAllCommand extends HyperionCommand {
private static final String NAME = "clearall";
public ClearAllCommand() {
super(NAME);
}
}

View File

@@ -0,0 +1,40 @@
/**
* 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.hyperion.internal.protocol.v1;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
/**
* The {@link ClearCommand} is a POJO for sending a Clear command
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class ClearCommand extends HyperionCommand {
private static final String NAME = "clear";
private int priority;
public ClearCommand(int priority) {
super(NAME);
setPriority(priority);
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}

View File

@@ -0,0 +1,47 @@
/**
* 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.hyperion.internal.protocol.v1;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Correction} is a POJO for an color correction on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class Correction {
@SerializedName("correctionValues")
private List<Integer> correctionValues = null;
@SerializedName("id")
private String id;
public List<Integer> getCorrectionValues() {
return correctionValues;
}
public void setCorrectionValues(List<Integer> correctionValues) {
this.correctionValues = correctionValues;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,49 @@
/**
* 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.hyperion.internal.protocol.v1;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Effect} is a POJO for an effect on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class Effect {
@SerializedName("name")
private String name;
@SerializedName("script")
private String script;
public Effect(String name) {
setName(name);
}
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -0,0 +1,45 @@
/**
* 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.hyperion.internal.protocol.v1;
import com.google.gson.annotations.SerializedName;
/**
* The {@link HyperionBuild} is a POJO for the Hyperion Build information on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class HyperionBuild {
@SerializedName("time")
private String time;
@SerializedName("version")
private String version;
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}

View File

@@ -0,0 +1,45 @@
/**
* 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.hyperion.internal.protocol.v1;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Priority} is a POJO for the priority information on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class Priority {
@SerializedName("priority")
private Integer priority;
@SerializedName("duration_ms")
private Integer durationMs;
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public Integer getDurationMs() {
return durationMs;
}
public void setDurationMs(Integer durationMs) {
this.durationMs = durationMs;
}
}

View File

@@ -0,0 +1,47 @@
/**
* 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.hyperion.internal.protocol.v1;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Temperature} is a POJO for temperature correction on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class Temperature {
@SerializedName("correctionValues")
private List<Integer> correctionValues = null;
@SerializedName("id")
private String id;
public List<Integer> getCorrectionValues() {
return correctionValues;
}
public void setCorrectionValues(List<Integer> correctionValues) {
this.correctionValues = correctionValues;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,135 @@
/**
* 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.hyperion.internal.protocol.v1;
import java.util.List;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Transform} is a POJO for a transformation on the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class Transform {
@SerializedName("blacklevel")
private List<Double> blacklevel = null;
@SerializedName("gamma")
private List<Double> gamma = null;
@SerializedName("id")
private String id;
@SerializedName("luminanceGain")
private Double luminanceGain;
@SerializedName("luminanceMinimum")
private Double luminanceMinimum;
@SerializedName("saturationGain")
private Double saturationGain;
@SerializedName("saturationLGain")
private Double saturationLGain;
@SerializedName("threshold")
private List<Double> threshold = null;
@SerializedName("valueGain")
private Double valueGain;
@SerializedName("whitelevel")
private List<Double> whitelevel = null;
public List<Double> getBlacklevel() {
return blacklevel;
}
public void setBlacklevel(List<Double> blacklevel) {
this.blacklevel = blacklevel;
}
public List<Double> getGamma() {
return gamma;
}
public void setGamma(List<Double> gamma) {
this.gamma = gamma;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Double getLuminanceGain() {
return luminanceGain;
}
public void setLuminanceGain(Double luminanceGain) {
this.luminanceGain = luminanceGain;
}
public Double getLuminanceMinimum() {
return luminanceMinimum;
}
public void setLuminanceMinimum(Double luminanceMinimum) {
this.luminanceMinimum = luminanceMinimum;
}
public Double getSaturationGain() {
return saturationGain;
}
public void setSaturationGain(Double saturationGain) {
this.saturationGain = saturationGain;
}
public Double getSaturationLGain() {
return saturationLGain;
}
public void setSaturationLGain(Double saturationLGain) {
this.saturationLGain = saturationLGain;
}
public List<Double> getThreshold() {
return threshold;
}
public void setThreshold(List<Double> threshold) {
this.threshold = threshold;
}
public Double getValueGain() {
return valueGain;
}
public void setValueGain(Double valueGain) {
this.valueGain = valueGain;
}
public List<Double> getWhitelevel() {
return whitelevel;
}
public void setWhitelevel(List<Double> whitelevel) {
this.whitelevel = whitelevel;
}
}

View File

@@ -0,0 +1,40 @@
/**
* 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.hyperion.internal.protocol.v1;
import org.openhab.binding.hyperion.internal.protocol.HyperionCommand;
/**
* The {@link TransformCommand} is a POJO for sending transform commands
* to the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class TransformCommand extends HyperionCommand {
private static final String NAME = "transform";
private Transform transform;
public TransformCommand(Transform transform) {
super(NAME);
setTransform(transform);
}
public Transform getTransform() {
return transform;
}
public void setTransform(Transform transform) {
this.transform = transform;
}
}

View File

@@ -0,0 +1,137 @@
/**
* 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.hyperion.internal.protocol.v1;
import java.util.List;
import org.openhab.binding.hyperion.internal.protocol.ng.Adjustment;
import com.google.gson.annotations.SerializedName;
/**
* The {@link V1Info} is a POJO for receiving information from a V1 Hyperion Server
*
* @author Daniel Walters - Initial contribution
*/
public class V1Info {
@SerializedName("activeEffects")
private List<ActiveEffect> activeEffects = null;
@SerializedName("activeLedColor")
private List<ActiveLedColor> activeLedColor = null;
@SerializedName("adjustment")
private List<Adjustment> adjustment = null;
@SerializedName("correction")
private List<Correction> correction = null;
@SerializedName("effects")
private List<Effect> effects = null;
@SerializedName("hostname")
private String hostname;
@SerializedName("hyperion_build")
private List<HyperionBuild> hyperionBuild = null;
@SerializedName("priorities")
private List<Priority> priorities = null;
@SerializedName("temperature")
private List<Temperature> temperature = null;
@SerializedName("transform")
private List<Transform> transform = null;
public List<ActiveEffect> getActiveEffects() {
return activeEffects;
}
public void setActiveEffects(List<ActiveEffect> activeEffects) {
this.activeEffects = activeEffects;
}
public List<ActiveLedColor> getActiveLedColor() {
return activeLedColor;
}
public void setActiveLedColor(List<ActiveLedColor> activeLedColor) {
this.activeLedColor = activeLedColor;
}
public List<Adjustment> getAdjustment() {
return adjustment;
}
public void setAdjustment(List<Adjustment> adjustment) {
this.adjustment = adjustment;
}
public List<Correction> getCorrection() {
return correction;
}
public void setCorrection(List<Correction> correction) {
this.correction = correction;
}
public List<Effect> getEffects() {
return effects;
}
public void setEffects(List<Effect> effects) {
this.effects = effects;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public List<HyperionBuild> getHyperionBuild() {
return hyperionBuild;
}
public void setHyperionBuild(List<HyperionBuild> hyperionBuild) {
this.hyperionBuild = hyperionBuild;
}
public List<Priority> getPriorities() {
return priorities;
}
public void setPriorities(List<Priority> priorities) {
this.priorities = priorities;
}
public List<Temperature> getTemperature() {
return temperature;
}
public void setTemperature(List<Temperature> temperature) {
this.temperature = temperature;
}
public List<Transform> getTransform() {
return transform;
}
public void setTransform(List<Transform> transform) {
this.transform = transform;
}
}

View File

@@ -0,0 +1,51 @@
/**
* 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.hyperion.internal.protocol.v1;
import com.google.gson.annotations.SerializedName;
/**
* The {@link Effect} is a POJO for a response from the Hyperion server.
*
* @author Daniel Walters - Initial contribution
*/
public class V1Response {
@SerializedName("command")
private String command;
@SerializedName("success")
private boolean success;
@SerializedName("tan")
private int tan;
@SerializedName("info")
private V1Info info;
public String getCommand() {
return command;
}
public boolean isSuccess() {
return success;
}
public int getTan() {
return tan;
}
public V1Info getInfo() {
return info;
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<binding:binding id="hyperion" 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>Hyperion Binding</name>
<description>This binding integrates openHAB with the Hyperion ambient lighting software.</description>
<author>Daniel Walters</author>
</binding:binding>

View File

@@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="hyperion"
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="serverV1">
<label>Hyperion Server</label>
<description>This is a Hyperion server</description>
<channels>
<channel id="brightness" typeId="brightness"/>
<channel id="color" typeId="color"/>
<channel id="effect" typeId="effect"/>
<channel id="clear" typeId="clear"/>
</channels>
<config-description>
<parameter name="host" type="text" required="true">
<label>Host Address</label>
<context>network-address</context>
<description>The host address of the Hyperion server JSON API.</description>
</parameter>
<parameter name="port" type="integer" required="false">
<label>Port</label>
<description>The port of the Hyperion server JSON API.</description>
<default>19444</default>
</parameter>
<parameter name="priority" type="integer" required="false">
<label>Priority</label>
<description>The priority associated with updates sent to the Hyperion server.</description>
<default>50</default>
</parameter>
<parameter name="poll_frequency" type="integer" required="false" min="1">
<label>Polling Frequency</label>
<description>How often (in seconds) to poll the Hyperion server for value changes.</description>
<default>15</default>
</parameter>
</config-description>
</thing-type>
<thing-type id="serverNG">
<label>Hyperion.ng Server</label>
<description>This is a Hyperion.ng server</description>
<channels>
<channel id="hyperionenabled" typeId="enabled"/>
<channel id="brightness" typeId="brightness"/>
<channel id="effect" typeId="effect"/>
<channel id="clear" typeId="clear"/>
<channel id="color" typeId="color"/>
<channel id="blackborder" typeId="blackborder"/>
<channel id="smoothing" typeId="smoothing"/>
<channel id="kodichecker" typeId="kodichecker"/>
<channel id="forwarder" typeId="forwarder"/>
<channel id="udplistener" typeId="udplistener"/>
<channel id="boblightserver" typeId="boblightserver"/>
<channel id="grabber" typeId="grabber"/>
<channel id="v4l" typeId="v4l"/>
<channel id="leddevice" typeId="leddevice"/>
</channels>
<config-description>
<parameter name="host" type="text" required="true">
<label>Host Address</label>
<context>network-address</context>
<description>The host address of the Hyperion server JSON API.</description>
</parameter>
<parameter name="port" type="integer" required="false">
<label>Port</label>
<description>The port of the Hyperion server JSON API.</description>
<default>19444</default>
</parameter>
<parameter name="priority" type="integer" required="false">
<label>Priority</label>
<description>The priority associated with updates sent to the Hyperion server.</description>
<default>50</default>
</parameter>
<parameter name="poll_frequency" type="integer" required="false" min="1">
<label>Polling Frequency</label>
<description>How often (in seconds) to poll the Hyperion server for value changes.</description>
<required>true</required>
<default>3</default>
</parameter>
<parameter name="origin" type="text" required="false">
<label>Origin</label>
<description>The origin used on color and effect commands.</description>
<default>openHAB</default>
<advanced>true</advanced>
</parameter>
</config-description>
</thing-type>
<channel-type id="brightness">
<item-type>Dimmer</item-type>
<label>Brightness</label>
<description>Sets the brightness of the LEDs</description>
</channel-type>
<channel-type id="color">
<item-type>Color</item-type>
<label>Color</label>
<description>Sets the color effect of the LEDs</description>
</channel-type>
<channel-type id="effect">
<item-type>String</item-type>
<label>Effect</label>
<description>Sets the effect of the LEDs</description>
</channel-type>
<channel-type id="clear" advanced="true">
<item-type>String</item-type>
<label>Clear Priority</label>
<description>Clears the given Hyperion priority</description>
</channel-type>
<channel-type id="enabled">
<item-type>Switch</item-type>
<label>Enabled</label>
<description>Shows whether Hyperion is currently enabled or not and allows enabling or disabling of Hyperion</description>
</channel-type>
<channel-type id="blackborder" advanced="true">
<item-type>Switch</item-type>
<label>Black Border</label>
<description>Shows the current state of the black border component and allows the black border component to be enabled
or disabled</description>
</channel-type>
<channel-type id="smoothing" advanced="true">
<item-type>Switch</item-type>
<label>Smoothing</label>
<description>Shows the current state of the smoothing component and allows the smoothing component to be enabled or
disabled</description>
</channel-type>
<channel-type id="kodichecker" advanced="true">
<item-type>Switch</item-type>
<label>Kodi Checker</label>
<description>Shows the current state of the Kodi checker component and allows the Kodi checker component to be enabled
or disabled</description>
</channel-type>
<channel-type id="forwarder" advanced="true">
<item-type>Switch</item-type>
<label>Forwarder</label>
<description>Shows the current state of the forwarder component and allows the forwarder component to be enabled or
disabled</description>
</channel-type>
<channel-type id="udplistener" advanced="true">
<item-type>Switch</item-type>
<label>UDP Listener</label>
<description>Shows the current state of the UDP listener component and allows the UDP listener component to be enabled
or disabled</description>
</channel-type>
<channel-type id="boblightserver" advanced="true">
<item-type>Switch</item-type>
<label>UDP Listener</label>
<description>Shows the current state of the Boblight server component and allows the Boblight server component to be
enabled or disabled</description>
</channel-type>
<channel-type id="grabber" advanced="true">
<item-type>Switch</item-type>
<label>Grabber</label>
<description>Shows the current state of the grabber component and allows the grabber component to be enabled or
disabled</description>
</channel-type>
<channel-type id="v4l" advanced="true">
<item-type>Switch</item-type>
<label>V4L Device</label>
<description>Shows the current state of the v4l component and allows the v4l component to be enabled or disabled</description>
</channel-type>
<channel-type id="leddevice" advanced="true">
<item-type>Switch</item-type>
<label>LED Device</label>
<description>Shows the current state of the LED component and allows the LED component to be enabled or disabled</description>
</channel-type>
</thing:thing-descriptions>