From 6f5b34958e26232415e43a4d1951f25903c75b10 Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Tue, 14 May 2019 10:59:58 +0200 Subject: [PATCH] Add acceleration to SmartPhone thing definition. --- ESH-INF/thing/thing-types.xml | 9 +++++++++ .../openlicht/handler/AbstractSmartWatchHandler.java | 10 ++++------ .../openlicht/handler/AbstractSmartphoneHandler.java | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ESH-INF/thing/thing-types.xml b/ESH-INF/thing/thing-types.xml index 3b9bf05..9ff3102 100644 --- a/ESH-INF/thing/thing-types.xml +++ b/ESH-INF/thing/thing-types.xml @@ -188,6 +188,15 @@ <channels> <channel typeId="brightness-type" id="brightness" /> + <channel typeId="acceleration-type" id="acceleration-x"> + <label>Acceleration X</label> + </channel> + <channel typeId="acceleration-type" id="acceleration-y"> + <label>Acceleration Y</label> + </channel> + <channel typeId="acceleration-type" id="acceleration-z"> + <label>Acceleration Z</label> + </channel> <channel typeId="rotation-type" id="rotation-x"> <label>Rotation X</label> </channel> diff --git a/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java index 1369c67..5e7c953 100644 --- a/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java +++ b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java @@ -24,6 +24,7 @@ import org.eclipse.smarthome.core.library.types.DecimalType; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.types.Command; +import org.eclipse.smarthome.core.types.RefreshType; import org.openhab.binding.openlicht.internal.ConfigurationHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,13 +69,10 @@ public abstract class AbstractSmartWatchHandler extends AbstractMqttHandler { @Override public void handleCommand(ChannelUID channelUID, Command command) { + if (command instanceof RefreshType) { + return; + } logger.debug("Got command for read-only thing: {} {}", channelUID.getAsString(), command.toFullString()); - // TODO: handle command - - // Note: if communication with thing fails for some reason, - // indicate that by setting the status with detail information - // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - // "Could not control device at IP address x.x.x.x"); } @Override diff --git a/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java index 52f92aa..6ba499c 100644 --- a/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java +++ b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java @@ -64,6 +64,11 @@ public abstract class AbstractSmartphoneHandler extends AbstractMqttHandler { case MQTT_CATEGORY_BRIGHTNESS: updateState(CHANNEL_BRIGHTNESS, new DecimalType(buffer.getFloat())); break; + case MQTT_CATEGORY_ACCELERATION: + doubleBuffer = buffer.asDoubleBuffer(); + updateState(CHANNEL_ACCELERATION_X, new DecimalType(doubleBuffer.get(0))); + updateState(CHANNEL_ACCELERATION_Y, new DecimalType(doubleBuffer.get(1))); + updateState(CHANNEL_ACCELERATION_Z, new DecimalType(doubleBuffer.get(2))); case MQTT_CATEGORY_ROTATION: doubleBuffer = buffer.asDoubleBuffer(); updateState(CHANNEL_ROTATION_X, new DecimalType(doubleBuffer.get(0))); @@ -78,6 +83,9 @@ public abstract class AbstractSmartphoneHandler extends AbstractMqttHandler { case MQTT_CATEGORY_BRIGHTNESS: updateState(CHANNEL_BRIGHTNESS, new DecimalType(Double.parseDouble(message))); break; + case MQTT_CATEGORY_ACCELERATION: + MqttUtils.handleAcceleration(message, this::updateState); + break; case MQTT_CATEGORY_ROTATION: MqttUtils.handleRotation(message, this::updateState); break; -- GitLab