Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hue] Added humidity and pressure sensor #7426

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions bundles/org.openhab.binding.hue/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
88 changes: 46 additions & 42 deletions bundles/org.openhab.binding.hue/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class FullSensor extends FullHueObject {
public static final String STATE_BUTTON_EVENT = "buttonevent";
public static final String STATE_PRESENCE = "presence";
public static final String STATE_TEMPERATURE = "temperature";
public static final String STATE_HUMIDITY = "humidity";
public static final String STATE_PRESSURE = "pressure";
public static final String STATE_LIGHT_LEVEL = "lightlevel";
public static final String STATE_DARK = "dark";
public static final String STATE_DAYLIGHT = "daylight";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class HueBindingConstants {
public static final ThingTypeUID THING_TYPE_CLIP_GENERIC_FLAG = new ThingTypeUID(BINDING_ID, "0850");
public static final ThingTypeUID THING_TYPE_PRESENCE_SENSOR = new ThingTypeUID(BINDING_ID, "0107");
public static final ThingTypeUID THING_TYPE_TEMPERATURE_SENSOR = new ThingTypeUID(BINDING_ID, "0302");
public static final ThingTypeUID THING_TYPE_HUMIDITY_SENSOR = new ThingTypeUID(BINDING_ID, "0405");
public static final ThingTypeUID THING_TYPE_PRESSURE_SENSOR = new ThingTypeUID(BINDING_ID, "0403");
public static final ThingTypeUID THING_TYPE_LIGHT_LEVEL_SENSOR = new ThingTypeUID(BINDING_ID, "0106");

// List all channels
Expand All @@ -62,6 +64,8 @@ public class HueBindingConstants {
public static final String CHANNEL_TAP_SWITCH = "tap_switch";
public static final String CHANNEL_PRESENCE = "presence";
public static final String CHANNEL_TEMPERATURE = "temperature";
public static final String CHANNEL_HUMIDITY = "humidity";
public static final String CHANNEL_PRESSURE = "pressure";
public static final String CHANNEL_LAST_UPDATED = "last_updated";
public static final String CHANNEL_BATTERY_LEVEL = "battery_level";
public static final String CHANNEL_BATTERY_LOW = "battery_low";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
import org.openhab.binding.hue.internal.handler.HueLightHandler;
import org.openhab.binding.hue.internal.handler.sensors.ClipHandler;
import org.openhab.binding.hue.internal.handler.sensors.DimmerSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.HumidityHandler;
import org.openhab.binding.hue.internal.handler.sensors.LightLevelHandler;
import org.openhab.binding.hue.internal.handler.sensors.PresenceHandler;
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
import org.openhab.binding.hue.internal.handler.sensors.PressureHandler;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Component;

Expand All @@ -61,6 +63,7 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
.of(HueBridgeHandler.SUPPORTED_THING_TYPES.stream(), HueLightHandler.SUPPORTED_THING_TYPES.stream(),
DimmerSwitchHandler.SUPPORTED_THING_TYPES.stream(), TapSwitchHandler.SUPPORTED_THING_TYPES.stream(),
PresenceHandler.SUPPORTED_THING_TYPES.stream(), TemperatureHandler.SUPPORTED_THING_TYPES.stream(),
HumidityHandler.SUPPORTED_THING_TYPES.stream(), PressureHandler.SUPPORTED_THING_TYPES.stream(),
LightLevelHandler.SUPPORTED_THING_TYPES.stream(), ClipHandler.SUPPORTED_THING_TYPES.stream())
.flatMap(i -> i).collect(Collectors.toSet()));

Expand All @@ -78,6 +81,8 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
|| TapSwitchHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| PresenceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| TemperatureHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| HumidityHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| PressureHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| LightLevelHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
|| ClipHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
ThingUID hueSensorUID = getSensorUID(thingTypeUID, thingUID, configuration, bridgeUID);
Expand Down Expand Up @@ -134,6 +139,10 @@ private ThingUID getThingUID(ThingTypeUID thingTypeUID, String id, @Nullable Thi
return new PresenceHandler(thing);
} else if (TemperatureHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new TemperatureHandler(thing);
} else if (HumidityHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new HumidityHandler(thing);
} else if (PressureHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new PressureHandler(thing);
} else if (LightLevelHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new LightLevelHandler(thing);
} else if (ClipHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
import org.openhab.binding.hue.internal.handler.LightStatusListener;
import org.openhab.binding.hue.internal.handler.SensorStatusListener;
import org.openhab.binding.hue.internal.handler.sensors.DimmerSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.HumidityHandler;
import org.openhab.binding.hue.internal.handler.sensors.LightLevelHandler;
import org.openhab.binding.hue.internal.handler.sensors.PresenceHandler;
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
import org.openhab.binding.hue.internal.handler.sensors.PressureHandler;
import org.openhab.binding.hue.internal.handler.sensors.ClipHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -68,7 +70,8 @@ public class HueLightDiscoveryService extends AbstractDiscoveryService
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.unmodifiableSet(Stream
.of(HueLightHandler.SUPPORTED_THING_TYPES.stream(), DimmerSwitchHandler.SUPPORTED_THING_TYPES.stream(),
TapSwitchHandler.SUPPORTED_THING_TYPES.stream(), PresenceHandler.SUPPORTED_THING_TYPES.stream(),
TemperatureHandler.SUPPORTED_THING_TYPES.stream(), LightLevelHandler.SUPPORTED_THING_TYPES.stream(),
TemperatureHandler.SUPPORTED_THING_TYPES.stream(), HumidityHandler.SUPPORTED_THING_TYPES.stream(),
PressureHandler.SUPPORTED_THING_TYPES.stream(), LightLevelHandler.SUPPORTED_THING_TYPES.stream(),
ClipHandler.SUPPORTED_THING_TYPES.stream())
.flatMap(i -> i).collect(Collectors.toSet()));

Expand All @@ -91,6 +94,8 @@ public class HueLightDiscoveryService extends AbstractDiscoveryService
new SimpleEntry<>("clipgenericflag", "0850"),
new SimpleEntry<>("zllpresence", "0107"),
new SimpleEntry<>("zlltemperature", "0302"),
new SimpleEntry<>("zllhumidity", "0405"),
new SimpleEntry<>("zllpressure", "0403"),
new SimpleEntry<>("zlllightlevel", "0106")
).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()));
// @formatter:on
Expand All @@ -112,7 +117,6 @@ public void deactivate() {
removeOlderResults(new Date().getTime(), hueBridgeHandler.getThing().getUID());
hueBridgeHandler.unregisterLightStatusListener(this);
hueBridgeHandler.unregisterSensorStatusListener(this);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.hue.internal.handler.sensors;

import static org.openhab.binding.hue.internal.FullSensor.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.unit.SmartHomeUnits;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.openhab.binding.hue.internal.FullSensor;
import org.openhab.binding.hue.internal.HueBridge;
import org.openhab.binding.hue.internal.SensorConfigUpdate;
import org.openhab.binding.hue.internal.TemperatureConfigUpdate;
import org.openhab.binding.hue.internal.handler.HueSensorHandler;

/**
* Temperature Sensor
*
* @author Johannes Ott - Initial contribution
*/
@NonNullByDefault
public class HumidityHandler extends HueSensorHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_HUMIDITY_SENSOR);

public HumidityHandler(Thing thing) {
super(thing);
}

@Override
protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
TemperatureConfigUpdate configUpdate = new TemperatureConfigUpdate();
if (configurationParameters.containsKey(CONFIG_LED_INDICATION)) {
configUpdate.setLedIndication(Boolean.TRUE.equals(configurationParameters.get(CONFIG_LED_INDICATION)));
}
return configUpdate;
}

@Override
protected void doSensorStateChanged(@Nullable HueBridge bridge, FullSensor sensor, Configuration config) {
Object humidity = sensor.getState().get(STATE_HUMIDITY);
if (humidity != null) {
BigDecimal value = new BigDecimal(String.valueOf(humidity));
updateState(CHANNEL_HUMIDITY,
new QuantityType<>(value.divide(new BigDecimal(100)), SmartHomeUnits.PERCENT));
}

if (sensor.getConfig().containsKey(CONFIG_LED_INDICATION)) {
config.put(CONFIG_LED_INDICATION, sensor.getConfig().get(CONFIG_LIGHT_LEVEL_THRESHOLD_DARK));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.hue.internal.handler.sensors;

import static org.openhab.binding.hue.internal.FullSensor.*;
import static org.openhab.binding.hue.internal.HueBindingConstants.*;
import static org.eclipse.smarthome.core.library.unit.MetricPrefix.*;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.core.library.types.QuantityType;
import org.eclipse.smarthome.core.library.unit.SIUnits;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.openhab.binding.hue.internal.FullSensor;
import org.openhab.binding.hue.internal.HueBridge;
import org.openhab.binding.hue.internal.SensorConfigUpdate;
import org.openhab.binding.hue.internal.TemperatureConfigUpdate;
import org.openhab.binding.hue.internal.handler.HueSensorHandler;

/**
* Pressure Sensor
*
* @author Johannes Ott - Initial contribution
*/
@NonNullByDefault
public class PressureHandler extends HueSensorHandler {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_PRESSURE_SENSOR);

public PressureHandler(Thing thing) {
super(thing);
}

@Override
protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
TemperatureConfigUpdate configUpdate = new TemperatureConfigUpdate();
if (configurationParameters.containsKey(CONFIG_LED_INDICATION)) {
configUpdate.setLedIndication(Boolean.TRUE.equals(configurationParameters.get(CONFIG_LED_INDICATION)));
}
return configUpdate;
}

@Override
protected void doSensorStateChanged(@Nullable HueBridge bridge, FullSensor sensor, Configuration config) {
Object pressure = sensor.getState().get(STATE_PRESSURE);
if (pressure != null) {
BigDecimal value = new BigDecimal(String.valueOf(pressure));
updateState(CHANNEL_PRESSURE, new QuantityType<>(value, HECTO(SIUnits.PASCAL)));
}

if (sensor.getConfig().containsKey(CONFIG_LED_INDICATION)) {
config.put(CONFIG_LED_INDICATION, sensor.getConfig().get(CONFIG_LIGHT_LEVEL_THRESHOLD_DARK));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<config-description:config-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd">

<config-description uri="thing-type:hue:light">
<parameter name="lightId" type="text">
<label>Light ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
</config-description>

<config-description uri="thing-type:hue:light_with_fade">
<parameter name="lightId" type="text">
<label>Light ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
<parameter name="fadetime" type="integer" min="0" step="100">
<label>Fade Time</label>
<description>Fade time in ms for changing values</description>
<default>400</default>
</parameter>
</config-description>

<config-description uri="thing-type:hue:plug">
<parameter name="lightId" type="text">
<label>Light ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
</config-description>

<config-description uri="thing-type:hue:plug_with_fade">
<parameter name="lightId" type="text">
<label>Light ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
<parameter name="fadetime" type="integer" min="0" step="100">
<label>Fade Time</label>
<description>Fade time in ms for changing values</description>
<default>400</default>
</parameter>
</config-description>

</config-description:config-descriptions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<config-description:config-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:config-description="https://openhab.org/schemas/config-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd">

<config-description uri="thing-type:hue:sensor">
<parameter name="sensorId" type="text">
<label>Sensor ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
<parameter name="on" type="boolean">
<label>Sensor Status</label>
<description>Enables or disables the sensor.</description>
</parameter>
</config-description>


<config-description uri="thing-type:hue:sensor_with_led">
<parameter name="sensorId" type="text">
<label>Sensor ID</label>
<description>The identifier that is used within the hue bridge.</description>
<required>true</required>
</parameter>
<parameter name="on" type="boolean">
<label>Sensor Status</label>
<description>Enables or disables the sensor.</description>
</parameter>
<parameter name="ledindication" type="boolean">
<label>LED Indication</label>
<description>Turns device LED during normal operation on or off. Devices might still indicate exceptional operation (Reset, SW Update, Battery Low).</description>
</parameter>
</config-description>

</config-description:config-descriptions>
Loading