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