2 * Copyright (c) 2010-2024 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.boschshc.internal.devices.twinguard;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*;
17 import java.util.List;
19 import javax.measure.quantity.Dimensionless;
20 import javax.measure.quantity.Temperature;
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;
34 * The Twinguard smoke detector warns you in case of fire and constantly monitors the air.
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
42 public class TwinguardHandler extends AbstractSmokeDetectorHandler {
44 public TwinguardHandler(Thing thing) {
49 protected void initializeServices() throws BoschSHCException {
50 super.initializeServices();
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));
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));