2 * Copyright (c) 2010-2023 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.thermostat;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.*;
17 import java.util.List;
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;
35 * Handler for a thermostat device.
37 * @author Christian Oeing - Initial contribution
38 * @author David Pace - Added silent mode service
41 public final class ThermostatHandler extends AbstractBatteryPoweredDeviceHandler {
43 private ChildLockService childLockService;
44 private SilentModeService silentModeService;
46 public ThermostatHandler(Thing thing) {
48 this.childLockService = new ChildLockService();
49 this.silentModeService = new SilentModeService();
53 protected void initializeServices() throws BoschSHCException {
54 super.initializeServices();
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));
63 public void handleCommand(ChannelUID channelUID, Command command) {
64 super.handleCommand(channelUID, command);
66 switch (channelUID.getId()) {
67 case CHANNEL_CHILD_LOCK:
68 this.handleServiceCommand(this.childLockService, command);
70 case CHANNEL_SILENT_MODE:
71 this.handleServiceCommand(this.silentModeService, command);
77 * Updates the channels which are linked to the {@link TemperatureLevelService}
80 * @param state Current state of {@link TemperatureLevelService}.
82 private void updateChannels(TemperatureLevelServiceState state) {
83 super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
87 * Updates the channels which are linked to the {@link ValveTappetService} of
90 * @param state Current state of {@link ValveTappetService}.
92 private void updateChannels(ValveTappetServiceState state) {
93 super.updateState(CHANNEL_VALVE_TAPPET_POSITION, state.getPositionState());
97 * Updates the channels which are linked to the {@link ChildLockService} of the
100 * @param state Current state of {@link ChildLockService}.
102 private void updateChannels(ChildLockServiceState state) {
103 super.updateState(CHANNEL_CHILD_LOCK, state.getActiveState());
107 * Updates the channels which are linked to the {@link SilentModeService} of the device.
109 * @param state current state of {@link SilentModeService}
111 private void updateChannels(SilentModeServiceState state) {
112 super.updateState(CHANNEL_SILENT_MODE, state.toOnOffType());