]> git.basschouten.com Git - openhab-addons.git/blob
4ccfc4ffe1be38b4eb8ba21f43e5578c17db546a
[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.boschshc.internal.devices.wallthermostat;
14
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.boschshc.internal.devices.AbstractBatteryPoweredDeviceHandler;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.humiditylevel.HumidityLevelService;
23 import org.openhab.binding.boschshc.internal.services.humiditylevel.dto.HumidityLevelServiceState;
24 import org.openhab.binding.boschshc.internal.services.temperaturelevel.TemperatureLevelService;
25 import org.openhab.binding.boschshc.internal.services.temperaturelevel.dto.TemperatureLevelServiceState;
26 import org.openhab.core.thing.Thing;
27
28 /**
29  * Handler for a wall thermostat device.
30  *
31  * @author Christian Oeing - Initial contribution
32  */
33 @NonNullByDefault
34 public final class WallThermostatHandler extends AbstractBatteryPoweredDeviceHandler {
35
36     public WallThermostatHandler(Thing thing) {
37         super(thing);
38     }
39
40     @Override
41     protected void initializeServices() throws BoschSHCException {
42         super.initializeServices();
43
44         this.createService(TemperatureLevelService::new, this::updateChannels, List.of(CHANNEL_TEMPERATURE));
45         this.createService(HumidityLevelService::new, this::updateChannels, List.of(CHANNEL_HUMIDITY));
46     }
47
48     /**
49      * Updates the channels which are linked to the {@link TemperatureLevelService} of the device.
50      *
51      * @param state Current state of {@link TemperatureLevelService}.
52      */
53     private void updateChannels(TemperatureLevelServiceState state) {
54         super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
55     }
56
57     /**
58      * Updates the channels which are linked to the {@link HumidityLevelService} of the device.
59      *
60      * @param state Current state of {@link HumidityLevelService}.
61      */
62     private void updateChannels(HumidityLevelServiceState state) {
63         super.updateState(CHANNEL_HUMIDITY, state.getHumidityState());
64     }
65 }