]> git.basschouten.com Git - openhab-addons.git/blob
fa731209765cc65aff008bb82241a97b6108ec54
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal.handler.sensors;
14
15 import static org.openhab.binding.hue.internal.FullSensor.STATE_PRESENCE;
16 import static org.openhab.binding.hue.internal.HueBindingConstants.*;
17
18 import java.util.Collections;
19 import java.util.Map;
20 import java.util.Set;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.hue.internal.FullSensor;
24 import org.openhab.binding.hue.internal.SensorConfigUpdate;
25 import org.openhab.binding.hue.internal.handler.HueSensorHandler;
26 import org.openhab.core.config.core.Configuration;
27 import org.openhab.core.library.types.OnOffType;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30
31 /**
32  * Geofence Presence Sensor
33  *
34  * @author Christoph Weitkamp - Initial contribution
35  */
36 @NonNullByDefault
37 public class GeofencePresenceHandler extends HueSensorHandler {
38     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.singleton(THING_TYPE_GEOFENCE_SENSOR);
39
40     public GeofencePresenceHandler(Thing thing) {
41         super(thing);
42     }
43
44     @Override
45     protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
46         return new SensorConfigUpdate();
47     }
48
49     @Override
50     protected void doSensorStateChanged(FullSensor sensor, Configuration config) {
51         Object presence = sensor.getState().get(STATE_PRESENCE);
52         if (presence != null) {
53             boolean value = Boolean.parseBoolean(String.valueOf(presence));
54             updateState(CHANNEL_PRESENCE, value ? OnOffType.ON : OnOffType.OFF);
55         }
56     }
57 }