]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hue] Added channel to enable / disable a motion sensor (#8721)
authorChristoph Weitkamp <github@christophweitkamp.de>
Fri, 16 Oct 2020 22:59:56 +0000 (00:59 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Oct 2020 22:59:56 +0000 (15:59 -0700)
* Added channel to activate/deactivate a motion sensor
* Applied spotless

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.hue/README.md
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBindingConstants.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueSensorHandler.java
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/sensors/PresenceHandler.java
bundles/org.openhab.binding.hue/src/main/resources/OH-INF/thing/PresenceSensor.xml

index 5580dca06aeb4159aeb52d6a42e424e1c96af664..816f77bb9376f9ad15c58dfda7d3f95a149c0251 100644 (file)
@@ -165,27 +165,28 @@ The group type also have an optional configuration value to specify the fade tim
 
 The devices support some of the following channels:
 
-| Channel Type ID   | Item Type          | Description                                                                                                                             | Thing types supporting this channel |
-|-------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------|
-| switch            | Switch             | This channel supports switching the device on and off.                                                                                  | 0000, 0010, group                   |
-| color             | Color              | This channel supports full color control with hue, saturation and brightness values.                                                    | 0200, 0210, group                   |
-| brightness        | Dimmer             | This channel supports adjusting the brightness value. Note that this is not available, if the color channel is supported.               | 0100, 0110, 0220, group             |
-| color_temperature | Dimmer             | This channel supports adjusting the color temperature from cold (0%) to warm (100%).                                                    | 0210, 0220, group                   |
-| alert             | String             | This channel supports displaying alerts by flashing the bulb either once or multiple times. Valid values are: NONE, SELECT and LSELECT. | 0000, 0100, 0200, 0210, 0220, group |
-| effect            | Switch             | This channel supports color looping.                                                                                                    | 0200, 0210, 0220                    |
-| dimmer_switch     | Number             | This channel shows which button was last pressed on the dimmer switch.                                                                  | 0820                                |
-| illuminance       | Number:Illuminance | This channel shows the current illuminance measured by the sensor.                                                                      | 0106                                |
-| light_level       | Number             | This channel shows the current light level measured by the sensor. **Advanced**                                                         | 0106                                |
-| dark              | Switch             | This channel indicates whether the light level is below the darkness threshold or not.                                                  | 0106                                |
-| daylight          | Switch             | This channel indicates whether the light level is below the daylight threshold or not.                                                  | 0106                                |
-| presence          | Switch             | This channel indicates whether a motion is detected by the sensor or not.                                                               | 0107                                |
-| temperature       | Number:Temperature | This channel shows the current temperature measured by the sensor.                                                                      | 0302                                |
-| flag              | Switch             | This channel save flag state for a CLIP sensor.                                                                                         | 0850                                |
-| status            | Number             | This channel save status state for a CLIP sensor.                                                                                       | 0840                                |
-| last_updated      | DateTime           | This channel the date and time when the sensor was last updated.                                                                        | 0820, 0830, 0840, 0850, 0106, 0107, 0302|
-| battery_level     | Number             | This channel shows the battery level.                                                                                                   | 0820, 0106, 0107, 0302              |
-| battery_low       | Switch             | This channel indicates whether the battery is low or not.                                                                               | 0820, 0106, 0107, 0302              |
-| scene             | String             | This channel activates the scene with the given ID String. The ID String of each scene is assigned by the Hue bridge.                   | bridge, group |
+| Channel Type ID   | Item Type          | Description                                                                                                                             | Thing types supporting this channel      |
+|-------------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------|
+| switch            | Switch             | This channel supports switching the device on and off.                                                                                  | 0000, 0010, group                        |
+| color             | Color              | This channel supports full color control with hue, saturation and brightness values.                                                    | 0200, 0210, group                        |
+| brightness        | Dimmer             | This channel supports adjusting the brightness value. Note that this is not available, if the color channel is supported.               | 0100, 0110, 0220, group                  |
+| color_temperature | Dimmer             | This channel supports adjusting the color temperature from cold (0%) to warm (100%).                                                    | 0210, 0220, group                        |
+| alert             | String             | This channel supports displaying alerts by flashing the bulb either once or multiple times. Valid values are: NONE, SELECT and LSELECT. | 0000, 0100, 0200, 0210, 0220, group      |
+| effect            | Switch             | This channel supports color looping.                                                                                                    | 0200, 0210, 0220                         |
+| dimmer_switch     | Number             | This channel shows which button was last pressed on the dimmer switch.                                                                  | 0820                                     |
+| illuminance       | Number:Illuminance | This channel shows the current illuminance measured by the sensor.                                                                      | 0106                                     |
+| light_level       | Number             | This channel shows the current light level measured by the sensor. **Advanced**                                                         | 0106                                     |
+| dark              | Switch             | This channel indicates whether the light level is below the darkness threshold or not.                                                  | 0106                                     |
+| daylight          | Switch             | This channel indicates whether the light level is below the daylight threshold or not.                                                  | 0106                                     |
+| presence          | Switch             | This channel indicates whether a motion is detected by the sensor or not.                                                               | 0107                                     |
+| enabled           | Switch             | This channel activated or deactivates the sensor                                                                                        | 0107                                     |
+| temperature       | Number:Temperature | This channel shows the current temperature measured by the sensor.                                                                      | 0302                                     |
+| flag              | Switch             | This channel save flag state for a CLIP sensor.                                                                                         | 0850                                     |
+| status            | Number             | This channel save status state for a CLIP sensor.                                                                                       | 0840                                     |
+| last_updated      | DateTime           | This channel the date and time when the sensor was last updated.                                                                        | 0820, 0830, 0840, 0850, 0106, 0107, 0302 |
+| battery_level     | Number             | This channel shows the battery level.                                                                                                   | 0820, 0106, 0107, 0302                   |
+| battery_low       | Switch             | This channel indicates whether the battery is low or not.                                                                               | 0820, 0106, 0107, 0302                   |
+| scene             | String             | This channel activates the scene with the given ID String. The ID String of each scene is assigned by the Hue bridge.                   | bridge, group                            |
 
 To load a hue scene inside a rule for example, the ID of the scene will be required.
 You can list all the scene IDs with the following console commands: `hue <bridgeUID> scenes` and `hue <groupThingUID> scenes`.
index 1e3f23eae00d6beba9ba041fb688070ce8436371..c542804a4728f50a969dbf8a879100bd3cbcea2c 100644 (file)
@@ -66,6 +66,7 @@ public class HueBindingConstants {
     public static final String CHANNEL_DIMMER_SWITCH = "dimmer_switch";
     public static final String CHANNEL_TAP_SWITCH = "tap_switch";
     public static final String CHANNEL_PRESENCE = "presence";
+    public static final String CHANNEL_ENABLED = "enabled";
     public static final String CHANNEL_TEMPERATURE = "temperature";
     public static final String CHANNEL_LAST_UPDATED = "last_updated";
     public static final String CHANNEL_BATTERY_LEVEL = "battery_level";
index 9c0d1aa198bb460324d708a72fc39ab53f2594a0..dde64f1d2b7e9830fdae789a0225d2c872669188 100644 (file)
@@ -64,7 +64,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
 
     private @Nullable HueClient hueClient;
 
-    private @Nullable FullSensor lastFullSensor;
+    protected @Nullable FullSensor lastFullSensor;
 
     public HueSensorHandler(Thing thing) {
         super(thing);
@@ -164,7 +164,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
         handleCommand(channelUID.getId(), command);
     }
 
-    public void handleCommand(String channel, Command command) {
+    protected void handleCommand(String channel, Command command) {
         HueClient bridgeHandler = getHueClient();
         if (bridgeHandler == null) {
             logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
@@ -172,7 +172,6 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
         }
 
         final FullSensor sensor = lastFullSensor;
-
         if (sensor == null) {
             logger.debug("hue sensor not known on bridge. Cannot handle command.");
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
@@ -213,7 +212,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
 
             final FullSensor sensor = lastFullSensor;
             if (sensor == null) {
-                logger.debug("hue sensor not known on bridge. Cannot handle command.");
+                logger.debug("hue sensor not known on bridge. Cannot handle configuration update.");
                 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
                         "@text/offline.conf-error-wrong-sensor-id");
                 return;
index 87b4b0f55c249246ee4f4c6d8332e89eaf9e394e..a80e2b0d9472d497c07f1047b205da86ddacf709 100644 (file)
@@ -23,11 +23,17 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.openhab.binding.hue.internal.FullSensor;
 import org.openhab.binding.hue.internal.PresenceConfigUpdate;
 import org.openhab.binding.hue.internal.SensorConfigUpdate;
+import org.openhab.binding.hue.internal.handler.HueClient;
 import org.openhab.binding.hue.internal.handler.HueSensorHandler;
 import org.openhab.core.config.core.Configuration;
 import org.openhab.core.library.types.OnOffType;
 import org.openhab.core.thing.Thing;
+import org.openhab.core.thing.ThingStatus;
+import org.openhab.core.thing.ThingStatusDetail;
 import org.openhab.core.thing.ThingTypeUID;
+import org.openhab.core.types.Command;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Presence Sensor
@@ -39,10 +45,38 @@ import org.openhab.core.thing.ThingTypeUID;
 public class PresenceHandler extends HueSensorHandler {
     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_PRESENCE_SENSOR);
 
+    private final Logger logger = LoggerFactory.getLogger(PresenceHandler.class);
+
     public PresenceHandler(Thing thing) {
         super(thing);
     }
 
+    @Override
+    public void handleCommand(String channel, Command command) {
+        HueClient hueBridge = getHueClient();
+        if (hueBridge == null) {
+            logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
+            return;
+        }
+
+        final FullSensor sensor = lastFullSensor;
+        if (sensor == null) {
+            logger.debug("hue sensor not known on bridge. Cannot handle command.");
+            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
+                    "@text/offline.conf-error-wrong-sensor-id");
+            return;
+        }
+
+        SensorConfigUpdate configUpdate = new SensorConfigUpdate();
+        switch (channel) {
+            case CHANNEL_ENABLED:
+                configUpdate.setOn(OnOffType.ON.equals(command));
+                break;
+        }
+
+        hueBridge.updateSensorConfig(sensor, configUpdate);
+    }
+
     @Override
     protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
         PresenceConfigUpdate configUpdate = new PresenceConfigUpdate();
index d4790ff8c846c351594d0aa29f9604bd515d6c29..7b31dc97d1726f9698807a62f16e74113fe03dca 100644 (file)
@@ -15,6 +15,7 @@
                <channels>
                        <channel id="presence" typeId="system.motion"/>
                        <channel id="last_updated" typeId="last_updated"/>
+                       <channel id="enabled" typeId="system.power"/>
                        <channel id="battery_level" typeId="system.battery-level"/>
                        <channel id="battery_low" typeId="system.low-battery"/>
                </channels>