]> git.basschouten.com Git - openhab-addons.git/blob
33de80c482173d86c2848cb5f8ee5220ff740f58
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.CHANNEL_CHILD_LOCK;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_TEMPERATURE;
17 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_VALVE_TAPPET_POSITION;
18
19 import java.util.List;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.boschshc.internal.devices.BoschSHCHandler;
23 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
24 import org.openhab.binding.boschshc.internal.services.childlock.ChildLockService;
25 import org.openhab.binding.boschshc.internal.services.childlock.dto.ChildLockServiceState;
26 import org.openhab.binding.boschshc.internal.services.temperaturelevel.TemperatureLevelService;
27 import org.openhab.binding.boschshc.internal.services.temperaturelevel.dto.TemperatureLevelServiceState;
28 import org.openhab.binding.boschshc.internal.services.valvetappet.ValveTappetService;
29 import org.openhab.binding.boschshc.internal.services.valvetappet.dto.ValveTappetServiceState;
30 import org.openhab.core.thing.ChannelUID;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.types.Command;
33
34 /**
35  * Handler for a thermostat device.
36  * 
37  * @author Christian Oeing - Initial contribution
38  */
39 @NonNullByDefault
40 public final class ThermostatHandler extends BoschSHCHandler {
41
42     private ChildLockService childLockService;
43
44     public ThermostatHandler(Thing thing) {
45         super(thing);
46         this.childLockService = new ChildLockService();
47     }
48
49     @Override
50     protected void initializeServices() throws BoschSHCException {
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 }