]> git.basschouten.com Git - openhab-addons.git/blob
05ee7e892b463b6aad47e5e34e909cf8b62a2236
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.netatmo.internal.handler.capability;
14
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.CHANNEL_FLOODLIGHT;
16
17 import java.util.List;
18
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;
29
30 /**
31  * {@link PresenceCapability} give to handle Presence Camera specifics
32  *
33  * @author GaĆ«l L'hopital - Initial contribution
34  *
35  */
36 @NonNullByDefault
37 public class PresenceCapability extends CameraCapability {
38     private final Logger logger = LoggerFactory.getLogger(PresenceCapability.class);
39
40     public PresenceCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
41             List<ChannelHelper> channelHelpers) {
42         super(handler, descriptionProvider, channelHelpers);
43     }
44
45     @Override
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);
50                 return;
51             } else if (command instanceof StringType) {
52                 try {
53                     FloodLightMode mode = FloodLightMode.valueOf(command.toString());
54                     changeFloodlightMode(mode);
55                 } catch (IllegalArgumentException e) {
56                     logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
57                 }
58                 return;
59             }
60         }
61         super.handleCommand(channelName, command);
62     }
63
64     private void changeFloodlightMode(FloodLightMode mode) {
65         securityCapability.ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));
66     }
67 }