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.CHANNEL_SETPOINT_TEMPERATURE;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_TEMPERATURE;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.boschshc.internal.devices.BoschSHCDeviceHandler;
22 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
23 import org.openhab.binding.boschshc.internal.services.roomclimatecontrol.RoomClimateControlService;
24 import org.openhab.binding.boschshc.internal.services.roomclimatecontrol.dto.RoomClimateControlServiceState;
25 import org.openhab.binding.boschshc.internal.services.temperaturelevel.TemperatureLevelService;
26 import org.openhab.binding.boschshc.internal.services.temperaturelevel.dto.TemperatureLevelServiceState;
27 import org.openhab.core.library.types.QuantityType;
28 import org.openhab.core.library.unit.SIUnits;
29 import org.openhab.core.thing.ChannelUID;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.types.Command;
34 * A virtual device which controls up to six Bosch Smart Home radiator thermostats in a room.
36 * @author Christian Oeing - Initial contribution
39 public final class ClimateControlHandler extends BoschSHCDeviceHandler {
41 private RoomClimateControlService roomClimateControlService;
46 * @param thing The Bosch Smart Home device that should be handled.
48 public ClimateControlHandler(Thing thing) {
50 this.roomClimateControlService = new RoomClimateControlService();
54 protected void initializeServices() throws BoschSHCException {
55 super.createService(TemperatureLevelService::new, this::updateChannels, List.of(CHANNEL_TEMPERATURE));
56 super.registerService(this.roomClimateControlService, this::updateChannels,
57 List.of(CHANNEL_SETPOINT_TEMPERATURE));
61 public void handleCommand(ChannelUID channelUID, Command command) {
62 super.handleCommand(channelUID, command);
63 switch (channelUID.getId()) {
64 case CHANNEL_SETPOINT_TEMPERATURE:
65 if (command instanceof QuantityType<?>) {
66 updateSetpointTemperature((QuantityType<?>) command);
73 * Updates the channels which are linked to the {@link TemperatureLevelService} of the device.
75 * @param state Current state of {@link TemperatureLevelService}.
77 private void updateChannels(TemperatureLevelServiceState state) {
78 super.updateState(CHANNEL_TEMPERATURE, state.getTemperatureState());
82 * Updates the channels which are linked to the {@link RoomClimateControlService} of the device.
84 * @param state Current state of {@link RoomClimateControlService}.
86 private void updateChannels(RoomClimateControlServiceState state) {
87 super.updateState(CHANNEL_SETPOINT_TEMPERATURE, state.getSetpointTemperatureState());
91 * Sets the desired temperature for the device.
93 * @param quantityType Command which contains the new desired temperature.
95 private void updateSetpointTemperature(QuantityType<?> quantityType) {
96 QuantityType<?> celsiusType = quantityType.toUnit(SIUnits.CELSIUS);
97 if (celsiusType == null) {
98 logger.debug("Could not convert quantity command to celsius");
102 double setpointTemperature = celsiusType.doubleValue();
103 this.updateServiceState(this.roomClimateControlService,
104 new RoomClimateControlServiceState(setpointTemperature));