]> git.basschouten.com Git - openhab-addons.git/blob
ffc390f5e82755c11921b7fe5c8f1ada7b3e100e
[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.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         ParadoxIP150BridgeHandler bridge = (ParadoxIP150BridgeHandler) getBridge().getHandler();
53         ParadoxPanel panel = bridge.getPanel();
54         StringType panelState = panel.isOnline() ? STATE_ONLINE : STATE_OFFLINE;
55         updateState(PANEL_STATE_CHANNEL_UID, panelState);
56         ParadoxInformation panelInformation = panel.getPanelInformation();
57         if (panelInformation != null) {
58             updateProperty(PANEL_SERIAL_NUMBER_PROPERTY_NAME, panelInformation.getSerialNumber());
59             updateProperty(PANEL_TYPE_PROPERTY_NAME, panelInformation.getPanelType().name());
60             updateProperty(PANEL_HARDWARE_VERSION_PROPERTY_NAME, panelInformation.getHardwareVersion().toString());
61             updateProperty(PANEL_APPLICATION_VERSION_PROPERTY_NAME,
62                     panelInformation.getApplicationVersion().toString());
63             updateProperty(PANEL_BOOTLOADER_VERSION_PROPERTY_NAME, panelInformation.getBootLoaderVersion().toString());
64
65             updateState(PANEL_TIME, new DateTimeType(panel.getPanelTime()));
66             updateState(PANEL_INPUT_VOLTAGE, new QuantityType<ElectricPotential>(panel.getVdcLevel(), Units.VOLT));
67             updateState(PANEL_BOARD_VOLTAGE, new QuantityType<ElectricPotential>(panel.getDcLevel(), Units.VOLT));
68             updateState(PANEL_BATTERY_VOLTAGE,
69                     new QuantityType<ElectricPotential>(panel.getBatteryLevel(), Units.VOLT));
70         }
71     }
72 }