]> git.basschouten.com Git - openhab-addons.git/blob
6a6e242a843f77e67c27ec0b3fbd65bb70a3ce68
[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.silentmode.SilentModeService;
25 import org.openhab.binding.boschshc.internal.services.silentmode.dto.SilentModeServiceState;
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  * @author David Pace - Added silent mode service
39  */
40 @NonNullByDefault
41 public final class ThermostatHandler extends AbstractBatteryPoweredDeviceHandler {
42
43     private ChildLockService childLockService;
44     private SilentModeService silentModeService;
45
46     public ThermostatHandler(Thing thing) {
47         super(thing);
48         this.childLockService = new ChildLockService();
49         this.silentModeService = new SilentModeService();
50     }
51
52     @Override
53     protected void initializeServices() throws BoschSHCException {
54         super.initializeServices();
55
56         this.createService(TemperatureLevelService::new, this::updateChannels, List.of(CHANNEL_TEMPERATURE));
57         this.createService(ValveTappetService::new, this::updateChannels, List.of(CHANNEL_VALVE_TAPPET_POSITION));
58         this.registerService(this.childLockService, this::updateChannels, List.of(CHANNEL_CHILD_LOCK));
59         this.registerService(this.silentModeService, this::updateChannels, List.of(CHANNEL_SILENT_MODE));
60     }
61
62     @Override
63     public void handleCommand(ChannelUID channelUID, Command command) {
64         super.handleCommand(channelUID, command);
65
66         switch (channelUID.getId()) {
67             case CHANNEL_CHILD_LOCK:
68                 this.handleServiceCommand(this.childLockService, command);
69                 break;
70             case CHANNEL_SILENT_MODE:
71                 this.handleServiceCommand(this.silentModeService, command);
72                 break;
73         }
74     }
75
76     /**
77      * Updates the channels which are linked to the {@link TemperatureLevelService}
78      * of the device.
79      *
80      * @param state Current state of {@link TemperatureLevelService}.
81      */
82     private void updateChannels(TemperatureLevelServiceState state) {
83         super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
84     }
85
86     /**
87      * Updates the channels which are linked to the {@link ValveTappetService} of
88      * the device.
89      *
90      * @param state Current state of {@link ValveTappetService}.
91      */
92     private void updateChannels(ValveTappetServiceState state) {
93         super.updateState(CHANNEL_VALVE_TAPPET_POSITION, state.getPositionState());
94     }
95
96     /**
97      * Updates the channels which are linked to the {@link ChildLockService} of the
98      * device.
99      *
100      * @param state Current state of {@link ChildLockService}.
101      */
102     private void updateChannels(ChildLockServiceState state) {
103         super.updateState(CHANNEL_CHILD_LOCK, state.getActiveState());
104     }
105
106     /**
107      * Updates the channels which are linked to the {@link SilentModeService} of the device.
108      * 
109      * @param state current state of {@link SilentModeService}
110      */
111     private void updateChannels(SilentModeServiceState state) {
112         super.updateState(CHANNEL_SILENT_MODE, state.toOnOffType());
113     }
114 }