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.netatmo.internal.handler.capability;
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FloodLightMode;
21 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SirenStatus;
22 import org.openhab.binding.netatmo.internal.handler.CommonInterface;
23 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
24 import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.types.Command;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * {@link PresenceCapability} give to handle Presence Camera specifics
34 * @author Gaƫl L'hopital - Initial contribution
38 public class PresenceCapability extends CameraCapability {
39 private final Logger logger = LoggerFactory.getLogger(PresenceCapability.class);
41 public PresenceCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
42 List<ChannelHelper> channelHelpers) {
43 super(handler, descriptionProvider, channelHelpers);
47 public void handleCommand(String channelName, Command command) {
48 if (CHANNEL_FLOODLIGHT.equals(channelName)) {
49 if (command instanceof OnOffType) {
50 changeFloodlightMode(command == OnOffType.ON ? FloodLightMode.ON : FloodLightMode.OFF);
52 } else if (command instanceof StringType) {
54 changeFloodlightMode(FloodLightMode.valueOf(command.toString()));
55 } catch (IllegalArgumentException e) {
56 logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
60 } else if (CHANNEL_SIREN.equals(channelName) && command instanceof OnOffType) {
61 getSecurityCapability().ifPresent(cap -> cap.changeSirenStatus(handler.getId(),
62 command == OnOffType.ON ? SirenStatus.SOUND : SirenStatus.NO_SOUND));
65 super.handleCommand(channelName, command);
68 private void changeFloodlightMode(FloodLightMode mode) {
69 getSecurityCapability().ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));