]> git.basschouten.com Git - openhab-addons.git/blob
487b2154af77388219e53fa082679cc81a9be89d
[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.verisure.internal.handler;
14
15 import static org.openhab.binding.verisure.internal.VerisureBindingConstants.*;
16
17 import java.util.Set;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.verisure.internal.dto.VerisureBroadbandConnectionsDTO;
21 import org.openhab.core.library.types.OnOffType;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingTypeUID;
26
27 /**
28  * Handler for the Broadband COnnection thing type that Verisure provides.
29  *
30  * @author Jan Gustafsson - Initial contribution
31  *
32  */
33 @NonNullByDefault
34 public class VerisureBroadbandConnectionThingHandler extends VerisureThingHandler<VerisureBroadbandConnectionsDTO> {
35
36     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_BROADBAND_CONNECTION);
37
38     public VerisureBroadbandConnectionThingHandler(Thing thing) {
39         super(thing);
40     }
41
42     @Override
43     public Class<VerisureBroadbandConnectionsDTO> getVerisureThingClass() {
44         return VerisureBroadbandConnectionsDTO.class;
45     }
46
47     @Override
48     public synchronized void update(VerisureBroadbandConnectionsDTO thing) {
49         updateBroadbandConnection(thing);
50         updateStatus(ThingStatus.ONLINE);
51     }
52
53     private void updateBroadbandConnection(VerisureBroadbandConnectionsDTO vbcJSON) {
54         String testDate = vbcJSON.getData().getInstallation().getBroadband().getTestDate();
55         if (testDate != null) {
56             updateTimeStamp(testDate);
57             ChannelUID cuid = new ChannelUID(getThing().getUID(), CHANNEL_CONNECTED);
58             boolean broadbandConnected = vbcJSON.getData().getInstallation().getBroadband().isBroadbandConnected();
59             updateState(cuid, OnOffType.from(broadbandConnected));
60             updateInstallationChannels(vbcJSON);
61         }
62     }
63
64     @Override
65     public void updateTriggerChannel(String event) {
66     }
67 }