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.*;
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;
28 * The {@link SomfyTahomaMyfoxCameraHandler} is responsible for handling commands,
29 * which are sent to one of the channels of the Myfox camera.
31 * @author Ondrej Pecta - Initial contribution
34 public class SomfyTahomaMyfoxCameraHandler extends SomfyTahomaBaseThingHandler {
36 public SomfyTahomaMyfoxCameraHandler(Thing thing) {
38 stateNames.put(CLOUD_STATUS, CLOUD_DEVICE_STATUS_STATE);
39 stateNames.put(SHUTTER, MYFOX_SHUTTER_STATUS_STATE);
43 public void updateThingChannels(SomfyTahomaState state) {
44 if (MYFOX_SHUTTER_STATUS_STATE.equals(state.getName())) {
45 Channel ch = thing.getChannel(SHUTTER);
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));
51 } else if (CLOUD_DEVICE_STATUS_STATE.equals(state.getName())) {
52 Channel ch = thing.getChannel(CLOUD_STATUS);
54 State newState = parseTahomaState(ch.getAcceptedItemType(), state);
55 if (newState != null) {
56 updateState(ch.getUID(), newState);
63 public void handleCommand(ChannelUID channelUID, Command command) {
64 super.handleCommand(channelUID, command);
65 if (!SHUTTER.equals(channelUID.getId())) {
69 if (command instanceof RefreshType) {
72 if (command instanceof OnOffType) {
73 sendCommand(command.equals(OnOffType.ON) ? "open" : "close");