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.somfytahoma.internal.handler;
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.HEATING_LEVEL;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.somfytahoma.internal.model.SomfyTahomaState;
19 import org.openhab.core.library.types.OnOffType;
20 import org.openhab.core.library.types.PercentType;
21 import org.openhab.core.thing.Channel;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.openhab.core.types.State;
29 * The {@link SomfyTahomaExteriorHeatingSystemHandler} is responsible for handling commands,
30 * which are sent to one of the channels of the exterior heating system thing.
32 * @author Ondrej Pecta - Initial contribution
35 public class SomfyTahomaExteriorHeatingSystemHandler extends SomfyTahomaBaseThingHandler {
37 public SomfyTahomaExteriorHeatingSystemHandler(Thing thing) {
42 public void updateThingChannels(SomfyTahomaState state) {
43 if ("core:LevelState".equals(state.getName())) {
44 Channel chLevel = thing.getChannel(HEATING_LEVEL);
45 if (chLevel != null) {
46 State newState = parseTahomaState(state);
47 if (newState != null && newState instanceof PercentType) {
48 int value = ((PercentType) newState).intValue();
49 PercentType inverted = new PercentType(100 - value);
50 updateState(chLevel.getUID(), inverted);
57 public void handleCommand(ChannelUID channelUID, Command command) {
58 super.handleCommand(channelUID, command);
59 if (command instanceof RefreshType) {
61 } else if (HEATING_LEVEL.equals(channelUID.getId())) {
62 if (command instanceof OnOffType) {
63 sendCommand(command.toString().toLowerCase());
65 int inverted = 100 - toInteger(command);
66 sendCommand("setLevel", "[" + inverted + "]");