]> git.basschouten.com Git - openhab-addons.git/blob
87753416e8d2d3453fc73e23ab6e9116a547e2ec
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.paradoxalarm.internal.handlers;
14
15 import static org.openhab.binding.paradoxalarm.internal.handlers.ParadoxAlarmBindingConstants.*;
16
17 import javax.measure.quantity.ElectricPotential;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.paradoxalarm.internal.model.ParadoxInformation;
21 import org.openhab.binding.paradoxalarm.internal.model.ParadoxPanel;
22 import org.openhab.core.library.types.DateTimeType;
23 import org.openhab.core.library.types.QuantityType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.library.unit.Units;
26 import org.openhab.core.thing.Thing;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  * The {@link ParadoxPanelHandler} This is the handler that takes care of the panel related stuff.
32  *
33  * @author Konstantin Polihronov - Initial contribution
34  */
35 @NonNullByDefault
36 public class ParadoxPanelHandler extends EntityBaseHandler {
37
38     private final Logger logger = LoggerFactory.getLogger(ParadoxPanelHandler.class);
39
40     public ParadoxPanelHandler(Thing thing) {
41         super(thing);
42     }
43
44     @Override
45     public void initialize() {
46         super.initialize();
47         config = getConfigAs(PanelConfiguration.class);
48     }
49
50     @Override
51     protected void updateEntity() {
52         ParadoxPanel panel = ParadoxPanel.getInstance();
53         StringType panelState = panel.isOnline() ? STATE_ONLINE : STATE_OFFLINE;
54         updateState(PANEL_STATE_CHANNEL_UID, panelState);
55         ParadoxInformation panelInformation = panel.getPanelInformation();
56         if (panelInformation != null) {
57             updateProperty(PANEL_SERIAL_NUMBER_PROPERTY_NAME, panelInformation.getSerialNumber());
58             updateProperty(PANEL_TYPE_PROPERTY_NAME, panelInformation.getPanelType().name());
59             updateProperty(PANEL_HARDWARE_VERSION_PROPERTY_NAME, panelInformation.getHardwareVersion().toString());
60             updateProperty(PANEL_APPLICATION_VERSION_PROPERTY_NAME,
61                     panelInformation.getApplicationVersion().toString());
62             updateProperty(PANEL_BOOTLOADER_VERSION_PROPERTY_NAME, panelInformation.getBootLoaderVersion().toString());
63
64             updateState(PANEL_TIME, new DateTimeType(panel.getPanelTime()));
65             updateState(PANEL_INPUT_VOLTAGE, new QuantityType<ElectricPotential>(panel.getVdcLevel(), Units.VOLT));
66             updateState(PANEL_BOARD_VOLTAGE, new QuantityType<ElectricPotential>(panel.getDcLevel(), Units.VOLT));
67             updateState(PANEL_BATTERY_VOLTAGE,
68                     new QuantityType<ElectricPotential>(panel.getBatteryLevel(), Units.VOLT));
69         }
70     }
71 }