]> git.basschouten.com Git - openhab-addons.git/blob
88a86bbef5f4d086eb4290756827d62a57e0ecaf
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.somfytahoma.internal.handler;
14
15 import static org.openhab.binding.somfytahoma.internal.SomfyTahomaBindingConstants.HEATING_LEVEL;
16
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;
27
28 /**
29  * The {@link SomfyTahomaExteriorHeatingSystemHandler} is responsible for handling commands,
30  * which are sent to one of the channels of the exterior heating system thing.
31  *
32  * @author Ondrej Pecta - Initial contribution
33  */
34 @NonNullByDefault
35 public class SomfyTahomaExteriorHeatingSystemHandler extends SomfyTahomaBaseThingHandler {
36
37     public SomfyTahomaExteriorHeatingSystemHandler(Thing thing) {
38         super(thing);
39     }
40
41     @Override
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);
51                 }
52             }
53         }
54     }
55
56     @Override
57     public void handleCommand(ChannelUID channelUID, Command command) {
58         super.handleCommand(channelUID, command);
59         if (command instanceof RefreshType) {
60             return;
61         } else if (HEATING_LEVEL.equals(channelUID.getId())) {
62             if (command instanceof OnOffType) {
63                 sendCommand(command.toString().toLowerCase());
64             } else {
65                 int inverted = 100 - toInteger(command);
66                 sendCommand("setLevel", "[" + inverted + "]");
67             }
68         }
69     }
70 }