]> git.basschouten.com Git - openhab-addons.git/blob
fe24681294e5dd4df8ddd02a5b35c9baa587ddca
[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.thermostat;
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.childlock.ChildLockService;
23 import org.openhab.binding.boschshc.internal.services.childlock.dto.ChildLockServiceState;
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.binding.boschshc.internal.services.valvetappet.ValveTappetService;
27 import org.openhab.binding.boschshc.internal.services.valvetappet.dto.ValveTappetServiceState;
28 import org.openhab.core.thing.ChannelUID;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.types.Command;
31
32 /**
33  * Handler for a thermostat device.
34  *
35  * @author Christian Oeing - Initial contribution
36  */
37 @NonNullByDefault
38 public final class ThermostatHandler extends AbstractBatteryPoweredDeviceHandler {
39
40     private ChildLockService childLockService;
41
42     public ThermostatHandler(Thing thing) {
43         super(thing);
44         this.childLockService = new ChildLockService();
45     }
46
47     @Override
48     protected void initializeServices() throws BoschSHCException {
49         super.initializeServices();
50
51         this.createService(TemperatureLevelService::new, this::updateChannels, List.of(CHANNEL_TEMPERATURE));
52         this.createService(ValveTappetService::new, this::updateChannels, List.of(CHANNEL_VALVE_TAPPET_POSITION));
53         this.registerService(this.childLockService, this::updateChannels, List.of(CHANNEL_CHILD_LOCK));
54     }
55
56     @Override
57     public void handleCommand(ChannelUID channelUID, Command command) {
58         super.handleCommand(channelUID, command);
59
60         switch (channelUID.getId()) {
61             case CHANNEL_CHILD_LOCK:
62                 this.handleServiceCommand(this.childLockService, command);
63                 break;
64         }
65     }
66
67     /**
68      * Updates the channels which are linked to the {@link TemperatureLevelService}
69      * of the device.
70      *
71      * @param state Current state of {@link TemperatureLevelService}.
72      */
73     private void updateChannels(TemperatureLevelServiceState state) {
74         super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
75     }
76
77     /**
78      * Updates the channels which are linked to the {@link ValveTappetService} of
79      * the device.
80      *
81      * @param state Current state of {@link ValveTappetService}.
82      */
83     private void updateChannels(ValveTappetServiceState state) {
84         super.updateState(CHANNEL_VALVE_TAPPET_POSITION, state.getPositionState());
85     }
86
87     /**
88      * Updates the channels which are linked to the {@link ChildLockService} of the
89      * device.
90      *
91      * @param state Current state of {@link ChildLockService}.
92      */
93     private void updateChannels(ChildLockServiceState state) {
94         super.updateState(CHANNEL_CHILD_LOCK, state.getActiveState());
95     }
96 }