]> git.basschouten.com Git - openhab-addons.git/blob
35caf5ea791c531b7cad3beb65fdebc00ce7f95e
[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.freeboxos.internal.handler;
14
15 import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
19 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager;
20 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.EndpointState;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.types.Command;
26 import org.openhab.core.types.State;
27 import org.openhab.core.types.UnDefType;
28
29 /**
30  * The {@link KeyfobHandler} is responsible for handling everything associated to
31  * any Freebox Home keyfob thing type.
32  *
33  * @author GaĆ«l L'hopital - Initial contribution
34  */
35 @NonNullByDefault
36 public class KeyfobHandler extends HomeNodeHandler {
37
38     public KeyfobHandler(Thing thing) {
39         super(thing);
40     }
41
42     @Override
43     protected State getChannelState(HomeManager homeManager, String channelId, EndpointState state) {
44         String value = state.value();
45         if (value != null) {
46             switch (channelId) {
47                 case KEYFOB_ENABLE:
48                     return OnOffType.from(state.asBoolean());
49                 case NODE_BATTERY:
50                     return DecimalType.valueOf(value);
51             }
52         }
53         return UnDefType.NULL;
54     }
55
56     @Override
57     protected boolean executeSlotCommand(HomeManager homeManager, String channelId, Command command,
58             Configuration config, int intValue) throws FreeboxException {
59         if (KEYFOB_ENABLE.equals(channelId) && command instanceof OnOffType onOff) {
60             return getManager(HomeManager.class).putCommand(getClientId(), intValue, onOff);
61         }
62         return false;
63     }
64 }