]> git.basschouten.com Git - openhab-addons.git/blob
5bc4b6fed08c1dbceaf114af4fa6468c0dcde17b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.AbstractSmokeDetectorHandler;
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  * @author Christian Oeing - Add smoke detector service
39  * @author Gerd Zanker - AbstractSmokeDetectorHandler refactoring for reuse
40  */
41 @NonNullByDefault
42 public class TwinguardHandler extends AbstractSmokeDetectorHandler {
43
44     public TwinguardHandler(Thing thing) {
45         super(thing);
46     }
47
48     @Override
49     protected void initializeServices() throws BoschSHCException {
50         super.initializeServices();
51
52         this.createService(AirQualityLevelService::new, this::updateChannels,
53                 List.of(CHANNEL_TEMPERATURE, CHANNEL_TEMPERATURE_RATING, CHANNEL_HUMIDITY, CHANNEL_HUMIDITY_RATING,
54                         CHANNEL_PURITY, CHANNEL_PURITY_RATING, CHANNEL_AIR_DESCRIPTION, CHANNEL_COMBINED_RATING));
55     }
56
57     private void updateChannels(AirQualityLevelServiceState state) {
58         updateState(CHANNEL_TEMPERATURE, new QuantityType<Temperature>(state.temperature, SIUnits.CELSIUS));
59         updateState(CHANNEL_TEMPERATURE_RATING, new StringType(state.temperatureRating));
60         updateState(CHANNEL_HUMIDITY, new QuantityType<Dimensionless>(state.humidity, Units.PERCENT));
61         updateState(CHANNEL_HUMIDITY_RATING, new StringType(state.humidityRating));
62         updateState(CHANNEL_PURITY, new QuantityType<Dimensionless>(state.purity, Units.PARTS_PER_MILLION));
63         updateState(CHANNEL_PURITY_RATING, new StringType(state.purityRating));
64         updateState(CHANNEL_AIR_DESCRIPTION, new StringType(state.description));
65         updateState(CHANNEL_COMBINED_RATING, new StringType(state.combinedRating));
66     }
67 }