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.climatecontrol;
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.BoschSHCDeviceHandler;
21 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
22 import org.openhab.binding.boschshc.internal.services.roomclimatecontrol.RoomClimateControlService;
23 import org.openhab.binding.boschshc.internal.services.roomclimatecontrol.dto.RoomClimateControlServiceState;
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.core.library.types.QuantityType;
27 import org.openhab.core.library.unit.SIUnits;
28 import org.openhab.core.thing.ChannelUID;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.types.Command;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * A virtual device which controls up to six Bosch Smart Home radiator thermostats in a room.
37 * @author Christian Oeing - Initial contribution
40 public final class ClimateControlHandler extends BoschSHCDeviceHandler {
42 private final Logger logger = LoggerFactory.getLogger(getClass());
44 private RoomClimateControlService roomClimateControlService;
49 * @param thing The Bosch Smart Home device that should be handled.
51 public ClimateControlHandler(Thing thing) {
53 this.roomClimateControlService = new RoomClimateControlService();
57 protected void initializeServices() throws BoschSHCException {
58 super.createService(TemperatureLevelService::new, this::updateChannels, List.of(CHANNEL_TEMPERATURE));
59 super.registerService(this.roomClimateControlService, this::updateChannels,
60 List.of(CHANNEL_SETPOINT_TEMPERATURE));
64 public void handleCommand(ChannelUID channelUID, Command command) {
65 super.handleCommand(channelUID, command);
66 switch (channelUID.getId()) {
67 case CHANNEL_SETPOINT_TEMPERATURE:
68 if (command instanceof QuantityType<?> temperature) {
69 updateSetpointTemperature(temperature);
76 * Updates the channels which are linked to the {@link TemperatureLevelService} of the device.
78 * @param state Current state of {@link TemperatureLevelService}.
80 private void updateChannels(TemperatureLevelServiceState state) {
81 super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
85 * Updates the channels which are linked to the {@link RoomClimateControlService} of the device.
87 * @param state Current state of {@link RoomClimateControlService}.
89 private void updateChannels(RoomClimateControlServiceState state) {
90 super.updateState(CHANNEL_SETPOINT_TEMPERATURE, state.getSetpointTemperatureState());
94 * Sets the desired temperature for the device.
96 * @param quantityType Command which contains the new desired temperature.
98 private void updateSetpointTemperature(QuantityType<?> quantityType) {
99 QuantityType<?> celsiusType = quantityType.toUnit(SIUnits.CELSIUS);
100 if (celsiusType == null) {
101 logger.debug("Could not convert quantity command to celsius");
105 double setpointTemperature = celsiusType.doubleValue();
106 this.updateServiceState(this.roomClimateControlService,
107 new RoomClimateControlServiceState(setpointTemperature));