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