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.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;
33 * Handler for a thermostat device.
35 * @author Christian Oeing - Initial contribution
38 public final class ThermostatHandler extends AbstractBatteryPoweredDeviceHandler {
40 private ChildLockService childLockService;
42 public ThermostatHandler(Thing thing) {
44 this.childLockService = new ChildLockService();
48 protected void initializeServices() throws BoschSHCException {
49 super.initializeServices();
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));
57 public void handleCommand(ChannelUID channelUID, Command command) {
58 super.handleCommand(channelUID, command);
60 switch (channelUID.getId()) {
61 case CHANNEL_CHILD_LOCK:
62 this.handleServiceCommand(this.childLockService, command);
68 * Updates the channels which are linked to the {@link TemperatureLevelService}
71 * @param state Current state of {@link TemperatureLevelService}.
73 private void updateChannels(TemperatureLevelServiceState state) {
74 super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
78 * Updates the channels which are linked to the {@link ValveTappetService} of
81 * @param state Current state of {@link ValveTappetService}.
83 private void updateChannels(ValveTappetServiceState state) {
84 super.updateState(CHANNEL_VALVE_TAPPET_POSITION, state.getPositionState());
88 * Updates the channels which are linked to the {@link ChildLockService} of the
91 * @param state Current state of {@link ChildLockService}.
93 private void updateChannels(ChildLockServiceState state) {
94 super.updateState(CHANNEL_CHILD_LOCK, state.getActiveState());