2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hue.internal.handler.sensors;
15 import static org.openhab.binding.hue.internal.FullSensor.*;
16 import static org.openhab.binding.hue.internal.HueBindingConstants.*;
18 import java.util.Collections;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.hue.internal.FullSensor;
24 import org.openhab.binding.hue.internal.PresenceConfigUpdate;
25 import org.openhab.binding.hue.internal.SensorConfigUpdate;
26 import org.openhab.binding.hue.internal.handler.HueSensorHandler;
27 import org.openhab.core.config.core.Configuration;
28 import org.openhab.core.library.types.OnOffType;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
35 * @author Samuel Leisering - Initial contribution
36 * @author Christoph Weitkamp - Initial contribution
39 public class PresenceHandler extends HueSensorHandler {
40 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_PRESENCE_SENSOR);
42 public PresenceHandler(Thing thing) {
47 protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
48 PresenceConfigUpdate configUpdate = new PresenceConfigUpdate();
49 if (configurationParameters.containsKey(CONFIG_LED_INDICATION)) {
50 configUpdate.setLedIndication(Boolean.TRUE.equals(configurationParameters.get(CONFIG_LED_INDICATION)));
52 if (configurationParameters.containsKey(CONFIG_PRESENCE_SENSITIVITY)) {
53 configUpdate.setSensitivity(
54 Integer.parseInt(String.valueOf(configurationParameters.get(CONFIG_PRESENCE_SENSITIVITY))));
60 protected void doSensorStateChanged(FullSensor sensor, Configuration config) {
61 Object presence = sensor.getState().get(STATE_PRESENCE);
62 if (presence != null) {
63 boolean value = Boolean.parseBoolean(String.valueOf(presence));
64 updateState(CHANNEL_PRESENCE, value ? OnOffType.ON : OnOffType.OFF);
67 if (sensor.getConfig().containsKey(CONFIG_LED_INDICATION)) {
68 config.put(CONFIG_LED_INDICATION, sensor.getConfig().get(CONFIG_LIGHT_LEVEL_THRESHOLD_DARK));
70 if (sensor.getConfig().containsKey(CONFIG_PRESENCE_SENSITIVITY)) {
71 config.put(CONFIG_PRESENCE_SENSITIVITY, sensor.getConfig().get(CONFIG_PRESENCE_SENSITIVITY));
73 if (sensor.getConfig().containsKey(CONFIG_PRESENCE_SENSITIVITY_MAX)) {
74 config.put(CONFIG_PRESENCE_SENSITIVITY_MAX, sensor.getConfig().get(CONFIG_PRESENCE_SENSITIVITY_MAX));