]> git.basschouten.com Git - openhab-addons.git/blob
ba90fda06ed38744363a23ed0d637b8e4ed381ee
[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.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.rest.HomeManager;
19 import org.openhab.binding.freeboxos.internal.api.rest.HomeManager.EndpointState;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.QuantityType;
22 import org.openhab.core.library.types.StringType;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.State;
25 import org.openhab.core.types.UnDefType;
26
27 /**
28  * The {@link AlarmHandler} is responsible for handling everything associated to
29  * any Freebox Home Alarm thing type.
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  */
33 @NonNullByDefault
34 public class AlarmHandler extends HomeNodeHandler {
35
36     public AlarmHandler(Thing thing) {
37         super(thing);
38     }
39
40     @Override
41     protected State getChannelState(HomeManager homeManager, String channelId, EndpointState state) {
42         String value = state.value();
43
44         if (value == null) {
45             return UnDefType.NULL;
46         }
47
48         return switch (channelId) {
49             case NODE_BATTERY -> DecimalType.valueOf(value);
50             case ALARM_PIN -> StringType.valueOf(value);
51             case ALARM_SOUND, ALARM_VOLUME -> QuantityType.valueOf(value + " %");
52             case ALARM_TIMEOUT1, ALARM_TIMEOUT2, ALARM_TIMEOUT3 -> QuantityType.valueOf(value + " s");
53             default -> UnDefType.NULL;
54         };
55     }
56 }