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.boschshc.internal.devices.camera;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_CAMERA_NOTIFICATION;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.CHANNEL_PRIVACY_MODE;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.boschshc.internal.devices.BoschSHCDeviceHandler;
22 import org.openhab.binding.boschshc.internal.exceptions.BoschSHCException;
23 import org.openhab.binding.boschshc.internal.services.cameranotification.CameraNotificationService;
24 import org.openhab.binding.boschshc.internal.services.cameranotification.CameraNotificationState;
25 import org.openhab.binding.boschshc.internal.services.cameranotification.dto.CameraNotificationServiceState;
26 import org.openhab.binding.boschshc.internal.services.privacymode.PrivacyModeService;
27 import org.openhab.binding.boschshc.internal.services.privacymode.PrivacyModeState;
28 import org.openhab.binding.boschshc.internal.services.privacymode.dto.PrivacyModeServiceState;
29 import org.openhab.core.library.types.OnOffType;
30 import org.openhab.core.thing.ChannelUID;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.types.Command;
35 * Handler for security cameras.
37 * This implementation handles services and commands that are common to all cameras, which are currently:
40 * <li><code>PrivacyMode</code> - Controls whether the camera records images</li>
41 * <li><code>CameraNotification</code> - Enables or disables notifications for the camera</li>
45 * The Eyes outdoor camera advertises a <code>CameraLight</code> service, which unfortunately does not work properly.
46 * Valid states are <code>ON</code> and <code>OFF</code>.
47 * One of my two cameras returns <code>HTTP 204 (No Content)</code> when requesting the state.
48 * Once Bosch supports this service properly, a new subclass may be introduced for the Eyes outdoor camera.
50 * @author David Pace - Initial contribution
54 public class CameraHandler extends BoschSHCDeviceHandler {
56 private PrivacyModeService privacyModeService;
57 private CameraNotificationService cameraNotificationService;
59 public CameraHandler(Thing thing) {
61 this.privacyModeService = new PrivacyModeService();
62 this.cameraNotificationService = new CameraNotificationService();
66 protected void initializeServices() throws BoschSHCException {
67 super.initializeServices();
69 this.registerService(this.privacyModeService, this::updateChannels, List.of(CHANNEL_PRIVACY_MODE), true);
70 this.registerService(this.cameraNotificationService, this::updateChannels, List.of(CHANNEL_CAMERA_NOTIFICATION),
75 public void handleCommand(ChannelUID channelUID, Command command) {
76 super.handleCommand(channelUID, command);
78 switch (channelUID.getId()) {
79 case CHANNEL_PRIVACY_MODE:
80 if (command instanceof OnOffType) {
81 updatePrivacyModeState((OnOffType) command);
85 case CHANNEL_CAMERA_NOTIFICATION:
86 if (command instanceof OnOffType) {
87 updateCameraNotificationState((OnOffType) command);
93 private void updatePrivacyModeState(OnOffType command) {
94 PrivacyModeServiceState serviceState = new PrivacyModeServiceState();
95 serviceState.value = PrivacyModeState.from(command);
96 this.updateServiceState(this.privacyModeService, serviceState);
99 private void updateCameraNotificationState(OnOffType command) {
100 CameraNotificationServiceState serviceState = new CameraNotificationServiceState();
101 serviceState.value = CameraNotificationState.from(command);
102 this.updateServiceState(this.cameraNotificationService, serviceState);
105 private void updateChannels(PrivacyModeServiceState state) {
106 super.updateState(CHANNEL_PRIVACY_MODE, state.value.toOnOffType());
109 private void updateChannels(CameraNotificationServiceState state) {
110 super.updateState(CHANNEL_CAMERA_NOTIFICATION, state.value.toOnOffType());