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.netatmo.internal.handler.capability;
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_FLOODLIGHT;
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.handler.CommonInterface;
22 import org.openhab.binding.netatmo.internal.handler.channelhelper.ChannelHelper;
23 import org.openhab.binding.netatmo.internal.providers.NetatmoDescriptionProvider;
24 import org.openhab.core.library.types.OnOffType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.types.Command;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * {@link PresenceCapability} give to handle Presence Camera specifics
33 * @author Gaƫl L'hopital - Initial contribution
37 public class PresenceCapability extends CameraCapability {
38 private final Logger logger = LoggerFactory.getLogger(PresenceCapability.class);
40 public PresenceCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
41 List<ChannelHelper> channelHelpers) {
42 super(handler, descriptionProvider, channelHelpers);
46 public void handleCommand(String channelName, Command command) {
47 if (CHANNEL_FLOODLIGHT.equals(channelName)) {
48 if (command instanceof OnOffType) {
49 changeFloodlightMode(command == OnOffType.ON ? FloodLightMode.ON : FloodLightMode.OFF);
51 } else if (command instanceof StringType) {
53 FloodLightMode mode = FloodLightMode.valueOf(command.toString());
54 changeFloodlightMode(mode);
55 } catch (IllegalArgumentException e) {
56 logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
61 super.handleCommand(channelName, command);
64 private void changeFloodlightMode(FloodLightMode mode) {
65 getSecurityCapability().ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));