]> git.basschouten.com Git - openhab-addons.git/blob
a4b0f3ac8244d7bb3422943c279d6487cfa7fb16
[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.boschshc.internal.devices.twinguard;
14
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*;
16
17 import java.util.List;
18
19 import javax.measure.quantity.Dimensionless;
20 import javax.measure.quantity.Temperature;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
24 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
25 import org.openhab.binding.boschshc.internal.services.airqualitylevel.AirQualityLevelService;
26 import org.openhab.binding.boschshc.internal.services.airqualitylevel.dto.AirQualityLevelServiceState;
27 import org.openhab.core.library.types.QuantityType;
28 import org.openhab.core.library.types.StringType;
29 import org.openhab.core.library.unit.SIUnits;
30 import org.openhab.core.library.unit.Units;
31 import org.openhab.core.thing.Thing;
32
33 /**
34  * The Twinguard smoke detector warns you in case of fire and constantly monitors the air.
35  *
36  * @author Stefan Kästle - Initial contribution
37  * @author Christian Oeing - Use service instead of custom logic
38  */
39 @NonNullByDefault
40 public class TwinguardHandler extends AbstractBatteryPoweredDeviceHandler {
41
42     public TwinguardHandler(Thing thing) {
43         super(thing);
44     }
45
46     @Override
47     protected void initializeServices() throws BoschSHCException {
48         super.initializeServices();
49
50         this.createService(AirQualityLevelService::new, this::updateChannels,
51                 List.of(CHANNEL_TEMPERATURE, CHANNEL_TEMPERATURE_RATING, CHANNEL_HUMIDITY, CHANNEL_HUMIDITY_RATING,
52                         CHANNEL_PURITY, CHANNEL_PURITY_RATING, CHANNEL_AIR_DESCRIPTION, CHANNEL_COMBINED_RATING));
53     }
54
55     private void updateChannels(AirQualityLevelServiceState state) {
56         updateState(CHANNEL_TEMPERATURE, new QuantityType<Temperature>(state.temperature, SIUnits.CELSIUS));
57         updateState(CHANNEL_TEMPERATURE_RATING, new StringType(state.temperatureRating));
58         updateState(CHANNEL_HUMIDITY, new QuantityType<Dimensionless>(state.humidity, Units.PERCENT));
59         updateState(CHANNEL_HUMIDITY_RATING, new StringType(state.humidityRating));
60         updateState(CHANNEL_PURITY, new QuantityType<Dimensionless>(state.purity, Units.PARTS_PER_MILLION));
61         updateState(CHANNEL_PURITY_RATING, new StringType(state.purityRating));
62         updateState(CHANNEL_AIR_DESCRIPTION, new StringType(state.description));
63         updateState(CHANNEL_COMBINED_RATING, new StringType(state.combinedRating));
64     }
65 }