[hue] Added channel to enable / disable a motion sensor (#8721)
* Added channel to activate/deactivate a motion sensor * Applied spotless Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
committed by
GitHub
parent
a97e3eaf9e
commit
02963b8c99
@@ -166,7 +166,7 @@ The group type also have an optional configuration value to specify the fade tim
|
|||||||
The devices support some of the following channels:
|
The devices support some of the following channels:
|
||||||
|
|
||||||
| Channel Type ID | Item Type | Description | Thing types supporting this channel |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
||||||
@@ -179,6 +179,7 @@ The devices support some of the following channels:
|
|||||||
| dark | Switch | This channel indicates whether the light level is below the darkness threshold or not. | 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| flag | Switch | This channel save flag state for a CLIP sensor. | 0850 |
|
||||||
| status | Number | This channel save status state for a CLIP sensor. | 0840 |
|
| status | Number | This channel save status state for a CLIP sensor. | 0840 |
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public class HueBindingConstants {
|
|||||||
public static final String CHANNEL_DIMMER_SWITCH = "dimmer_switch";
|
public static final String CHANNEL_DIMMER_SWITCH = "dimmer_switch";
|
||||||
public static final String CHANNEL_TAP_SWITCH = "tap_switch";
|
public static final String CHANNEL_TAP_SWITCH = "tap_switch";
|
||||||
public static final String CHANNEL_PRESENCE = "presence";
|
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_TEMPERATURE = "temperature";
|
||||||
public static final String CHANNEL_LAST_UPDATED = "last_updated";
|
public static final String CHANNEL_LAST_UPDATED = "last_updated";
|
||||||
public static final String CHANNEL_BATTERY_LEVEL = "battery_level";
|
public static final String CHANNEL_BATTERY_LEVEL = "battery_level";
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
|
|||||||
|
|
||||||
private @Nullable HueClient hueClient;
|
private @Nullable HueClient hueClient;
|
||||||
|
|
||||||
private @Nullable FullSensor lastFullSensor;
|
protected @Nullable FullSensor lastFullSensor;
|
||||||
|
|
||||||
public HueSensorHandler(Thing thing) {
|
public HueSensorHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
@@ -164,7 +164,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
|
|||||||
handleCommand(channelUID.getId(), command);
|
handleCommand(channelUID.getId(), command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleCommand(String channel, Command command) {
|
protected void handleCommand(String channel, Command command) {
|
||||||
HueClient bridgeHandler = getHueClient();
|
HueClient bridgeHandler = getHueClient();
|
||||||
if (bridgeHandler == null) {
|
if (bridgeHandler == null) {
|
||||||
logger.warn("hue bridge handler not found. Cannot handle command without bridge.");
|
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;
|
final FullSensor sensor = lastFullSensor;
|
||||||
|
|
||||||
if (sensor == null) {
|
if (sensor == null) {
|
||||||
logger.debug("hue sensor not known on bridge. Cannot handle command.");
|
logger.debug("hue sensor not known on bridge. Cannot handle command.");
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
@@ -213,7 +212,7 @@ public abstract class HueSensorHandler extends BaseThingHandler implements Senso
|
|||||||
|
|
||||||
final FullSensor sensor = lastFullSensor;
|
final FullSensor sensor = lastFullSensor;
|
||||||
if (sensor == null) {
|
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,
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
|
||||||
"@text/offline.conf-error-wrong-sensor-id");
|
"@text/offline.conf-error-wrong-sensor-id");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -23,11 +23,17 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.openhab.binding.hue.internal.FullSensor;
|
import org.openhab.binding.hue.internal.FullSensor;
|
||||||
import org.openhab.binding.hue.internal.PresenceConfigUpdate;
|
import org.openhab.binding.hue.internal.PresenceConfigUpdate;
|
||||||
import org.openhab.binding.hue.internal.SensorConfigUpdate;
|
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.binding.hue.internal.handler.HueSensorHandler;
|
||||||
import org.openhab.core.config.core.Configuration;
|
import org.openhab.core.config.core.Configuration;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.thing.Thing;
|
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.thing.ThingTypeUID;
|
||||||
|
import org.openhab.core.types.Command;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presence Sensor
|
* Presence Sensor
|
||||||
@@ -39,10 +45,38 @@ import org.openhab.core.thing.ThingTypeUID;
|
|||||||
public class PresenceHandler extends HueSensorHandler {
|
public class PresenceHandler extends HueSensorHandler {
|
||||||
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_PRESENCE_SENSOR);
|
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) {
|
public PresenceHandler(Thing thing) {
|
||||||
super(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
|
@Override
|
||||||
protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
|
protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
|
||||||
PresenceConfigUpdate configUpdate = new PresenceConfigUpdate();
|
PresenceConfigUpdate configUpdate = new PresenceConfigUpdate();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<channels>
|
<channels>
|
||||||
<channel id="presence" typeId="system.motion"/>
|
<channel id="presence" typeId="system.motion"/>
|
||||||
<channel id="last_updated" typeId="last_updated"/>
|
<channel id="last_updated" typeId="last_updated"/>
|
||||||
|
<channel id="enabled" typeId="system.power"/>
|
||||||
<channel id="battery_level" typeId="system.battery-level"/>
|
<channel id="battery_level" typeId="system.battery-level"/>
|
||||||
<channel id="battery_low" typeId="system.low-battery"/>
|
<channel id="battery_low" typeId="system.low-battery"/>
|
||||||
</channels>
|
</channels>
|
||||||
|
|||||||
Reference in New Issue
Block a user