]> git.basschouten.com Git - openhab-addons.git/blob
040d9841b682ddcb484c6e8607b99a6c3ebcad6a
[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.*;
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.thing.Channel;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.types.Command;
24 import org.openhab.core.types.RefreshType;
25 import org.openhab.core.types.State;
26
27 /**
28  * The {@link SomfyTahomaMyfoxCameraHandler} is responsible for handling commands,
29  * which are sent to one of the channels of the Myfox camera.
30  *
31  * @author Ondrej Pecta - Initial contribution
32  */
33 @NonNullByDefault
34 public class SomfyTahomaMyfoxCameraHandler extends SomfyTahomaBaseThingHandler {
35
36     public SomfyTahomaMyfoxCameraHandler(Thing thing) {
37         super(thing);
38         stateNames.put(CLOUD_STATUS, CLOUD_DEVICE_STATUS_STATE);
39         stateNames.put(SHUTTER, MYFOX_SHUTTER_STATUS_STATE);
40     }
41
42     @Override
43     public void updateThingChannels(SomfyTahomaState state) {
44         if (MYFOX_SHUTTER_STATUS_STATE.equals(state.getName())) {
45             Channel ch = thing.getChannel(SHUTTER);
46             if (ch != null) {
47                 // we need to covert opened/closed values to ON/OFF
48                 boolean open = "opened".equals(state.getValue());
49                 updateState(ch.getUID(), OnOffType.from(open));
50             }
51         } else if (CLOUD_DEVICE_STATUS_STATE.equals(state.getName())) {
52             Channel ch = thing.getChannel(CLOUD_STATUS);
53             if (ch != null) {
54                 State newState = parseTahomaState(ch.getAcceptedItemType(), state);
55                 if (newState != null) {
56                     updateState(ch.getUID(), newState);
57                 }
58             }
59         }
60     }
61
62     @Override
63     public void handleCommand(ChannelUID channelUID, Command command) {
64         super.handleCommand(channelUID, command);
65         if (!SHUTTER.equals(channelUID.getId())) {
66             return;
67         }
68
69         if (command instanceof RefreshType) {
70             return;
71         } else {
72             if (command instanceof OnOffType) {
73                 sendCommand(command.equals(OnOffType.ON) ? "open" : "close");
74             }
75         }
76     }
77 }