]> git.basschouten.com Git - openhab-addons.git/blob
3a664bff22e87a21b6d3988079e2cf017648f596
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.HueBindingConstants.*;
16 import static org.openhab.binding.hue.internal.dto.FullSensor.*;
17
18 import java.math.BigDecimal;
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.dto.FullSensor;
24 import org.openhab.binding.hue.internal.dto.SensorConfigUpdate;
25 import org.openhab.binding.hue.internal.dto.TemperatureConfigUpdate;
26 import org.openhab.binding.hue.internal.handler.HueSensorHandler;
27 import org.openhab.core.config.core.Configuration;
28 import org.openhab.core.library.types.QuantityType;
29 import org.openhab.core.library.unit.SIUnits;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32
33 /**
34  * Temperature Sensor
35  *
36  * @author Samuel Leisering - Initial contribution
37  * @author Christoph Weitkamp - Initial contribution
38  */
39 @NonNullByDefault
40 public class TemperatureHandler extends HueSensorHandler {
41
42     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_TEMPERATURE_SENSOR);
43
44     public TemperatureHandler(Thing thing) {
45         super(thing);
46     }
47
48     @Override
49     protected SensorConfigUpdate doConfigurationUpdate(Map<String, Object> configurationParameters) {
50         TemperatureConfigUpdate configUpdate = new TemperatureConfigUpdate();
51         if (configurationParameters.containsKey(CONFIG_LED_INDICATION)) {
52             configUpdate.setLedIndication(Boolean.TRUE.equals(configurationParameters.get(CONFIG_LED_INDICATION)));
53         }
54         return configUpdate;
55     }
56
57     @Override
58     protected void doSensorStateChanged(FullSensor sensor, Configuration config) {
59         Object temperature = sensor.getState().get(STATE_TEMPERATURE);
60         if (temperature != null) {
61             BigDecimal value = new BigDecimal(String.valueOf(temperature));
62             updateState(CHANNEL_TEMPERATURE, new QuantityType<>(value.divide(new BigDecimal(100)), SIUnits.CELSIUS));
63         }
64
65         if (sensor.getConfig().containsKey(CONFIG_LED_INDICATION)) {
66             config.put(CONFIG_LED_INDICATION, sensor.getConfig().get(CONFIG_LED_INDICATION));
67         }
68     }
69 }