2 * Copyright (c) 2010-2022 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.CHANNEL_AIR_DESCRIPTION;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_COMBINED_RATING;
17 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_HUMIDITY;
18 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_HUMIDITY_RATING;
19 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_PURITY;
20 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_PURITY_RATING;
21 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_TEMPERATURE;
22 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_TEMPERATURE_RATING;
24 import java.util.List;
26 import javax.measure.quantity.Dimensionless;
27 import javax.measure.quantity.Temperature;
29 import org.eclipse.jdt.annotation.NonNullByDefault;
30 import org.openhab.binding.boschshc.internal.devices.BoschSHCHandler;
31 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
32 import org.openhab.binding.boschshc.internal.services.airqualitylevel.AirQualityLevelService;
33 import org.openhab.binding.boschshc.internal.services.airqualitylevel.dto.AirQualityLevelServiceState;
34 import org.openhab.core.library.types.QuantityType;
35 import org.openhab.core.library.types.StringType;
36 import org.openhab.core.library.unit.SIUnits;
37 import org.openhab.core.library.unit.Units;
38 import org.openhab.core.thing.Thing;
41 * The Twinguard smoke detector warns you in case of fire and constantly monitors the air.
43 * @author Stefan Kästle - Initial contribution
44 * @author Christian Oeing - Use service instead of custom logic
47 public class TwinguardHandler extends BoschSHCHandler {
49 public TwinguardHandler(Thing thing) {
54 protected void initializeServices() throws BoschSHCException {
55 super.initializeServices();
57 this.createService(AirQualityLevelService::new, this::updateChannels,
58 List.of(CHANNEL_TEMPERATURE, CHANNEL_TEMPERATURE_RATING, CHANNEL_HUMIDITY, CHANNEL_HUMIDITY_RATING,
59 CHANNEL_PURITY, CHANNEL_PURITY_RATING, CHANNEL_AIR_DESCRIPTION, CHANNEL_COMBINED_RATING));
62 private void updateChannels(AirQualityLevelServiceState state) {
63 updateState(CHANNEL_TEMPERATURE, new QuantityType<Temperature>(state.temperature, SIUnits.CELSIUS));
64 updateState(CHANNEL_TEMPERATURE_RATING, new StringType(state.temperatureRating));
65 updateState(CHANNEL_HUMIDITY, new QuantityType<Dimensionless>(state.humidity, Units.PERCENT));
66 updateState(CHANNEL_HUMIDITY_RATING, new StringType(state.humidityRating));
67 updateState(CHANNEL_PURITY, new QuantityType<Dimensionless>(state.purity, Units.PARTS_PER_MILLION));
68 updateState(CHANNEL_PURITY_RATING, new StringType(state.purityRating));
69 updateState(CHANNEL_AIR_DESCRIPTION, new StringType(state.description));
70 updateState(CHANNEL_COMBINED_RATING, new StringType(state.combinedRating));