]> git.basschouten.com Git - openhab-addons.git/blob
daac4367e23026ca1fca1e07cb140a54351f98fb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.*;
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.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;
30
31 /**
32  * {@link PresenceCapability} give to handle Presence Camera specifics
33  *
34  * @author GaĆ«l L'hopital - Initial contribution
35  *
36  */
37 @NonNullByDefault
38 public class PresenceCapability extends CameraCapability {
39     private final Logger logger = LoggerFactory.getLogger(PresenceCapability.class);
40
41     public PresenceCapability(CommonInterface handler, NetatmoDescriptionProvider descriptionProvider,
42             List<ChannelHelper> channelHelpers) {
43         super(handler, descriptionProvider, channelHelpers);
44     }
45
46     @Override
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);
51                 return;
52             } else if (command instanceof StringType) {
53                 try {
54                     changeFloodlightMode(FloodLightMode.valueOf(command.toString()));
55                 } catch (IllegalArgumentException e) {
56                     logger.info("Incorrect command '{}' received for channel '{}'", command, channelName);
57                 }
58                 return;
59             }
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));
63             return;
64         }
65         super.handleCommand(channelName, command);
66     }
67
68     private void changeFloodlightMode(FloodLightMode mode) {
69         getSecurityCapability().ifPresent(cap -> cap.changeFloodlightMode(handler.getId(), mode));
70     }
71 }