2 * Copyright (c) 2010-2024 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.ipcamera.internal;
15 import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*;
17 import java.util.ArrayList;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.ipcamera.internal.handler.IpCameraHandler;
22 import org.openhab.core.library.types.OnOffType;
23 import org.openhab.core.thing.ChannelUID;
24 import org.openhab.core.thing.binding.ThingHandler;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.RefreshType;
28 import io.netty.channel.ChannelDuplexHandler;
29 import io.netty.channel.ChannelHandlerContext;
30 import io.netty.util.ReferenceCountUtil;
33 * The {@link DoorBirdHandler} is responsible for handling commands, which are
34 * sent to one of the channels.
36 * @author Matthew Skinner - Initial contribution
40 public class DoorBirdHandler extends ChannelDuplexHandler {
41 private IpCameraHandler ipCameraHandler;
43 public DoorBirdHandler(ThingHandler handler) {
44 ipCameraHandler = (IpCameraHandler) handler;
47 // This handles the incoming http replies back from the camera.
49 public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object msg) throws Exception {
50 if (msg == null || ctx == null) {
54 String content = msg.toString();
55 ipCameraHandler.logger.trace("HTTP Result back from camera is \t:{}:", content);
56 if (content.contains("doorbell:L")) {
57 ipCameraHandler.setChannelState(CHANNEL_DOORBELL, OnOffType.OFF);
58 } else if (content.contains("doorbell:H")) {
59 ipCameraHandler.setChannelState(CHANNEL_DOORBELL, OnOffType.ON);
61 if (content.contains("motionsensor:L")) {
62 ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
63 } else if (content.contains("motionsensor:H")) {
64 ipCameraHandler.motionDetected(CHANNEL_MOTION_ALARM);
67 ReferenceCountUtil.release(msg);
71 // This handles the commands that come from the Openhab event bus.
72 public void handleCommand(ChannelUID channelUID, Command command) {
73 if (command instanceof RefreshType) {
76 switch (channelUID.getId()) {
77 case CHANNEL_ACTIVATE_ALARM_OUTPUT:
78 if (OnOffType.ON.equals(command)) {
79 ipCameraHandler.sendHttpGET("/bha-api/open-door.cgi");
82 case CHANNEL_ACTIVATE_ALARM_OUTPUT2:
83 if (OnOffType.ON.equals(command)) {
84 ipCameraHandler.sendHttpGET("/bha-api/open-door.cgi?r=2");
87 case CHANNEL_EXTERNAL_LIGHT:
88 if (OnOffType.ON.equals(command)) {
89 ipCameraHandler.sendHttpGET("/bha-api/light-on.cgi");
95 // If a camera does not need to poll a request as often as snapshots, it can be
96 // added here. Binding steps through the list.
97 public ArrayList<String> getLowPriorityRequests() {
98 return new ArrayList<String>(1);