]> git.basschouten.com Git - openhab-addons.git/blob
b5a57c73784fb153d99351d7462d74f5a4ebf8b0
[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.wlanthermo.internal.api.mini;
14
15 import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jetty.client.HttpClient;
19 import org.openhab.binding.wlanthermo.internal.*;
20 import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App;
21 import org.openhab.core.thing.*;
22 import org.openhab.core.types.Command;
23 import org.openhab.core.types.State;
24
25 /**
26  * The {@link WlanThermoMiniHandler} is responsible for handling commands, which are
27  * sent to one of the channels.
28  *
29  * @author Christian Schlipp - Initial contribution
30  */
31 @NonNullByDefault
32 public class WlanThermoMiniHandler extends WlanThermoHandler {
33
34     private App app = new App();
35
36     public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) {
37         super(thing, httpClient, false);
38     }
39
40     @Override
41     protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException {
42         return WlanThermoMiniCommandHandler.getState(channelUID, app);
43     }
44
45     @Override
46     protected boolean setState(ChannelUID channelUID, Command command) {
47         // Mini is read-only!
48         return false;
49     }
50
51     @Override
52     protected void push() {
53         // Unused, Mini is read-only!
54     }
55
56     @Override
57     protected void pull() {
58         try {
59             // Update objects with data from device
60             app = doGet("/app.php", App.class);
61
62             // Update channels
63             for (Channel channel : thing.getChannels()) {
64                 try {
65                     State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app);
66                     updateState(channel.getUID(), state);
67                 } catch (WlanThermoUnknownChannelException e) {
68                     // if we could not obtain a state, try trigger instead
69                     try {
70                         String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app);
71                         if (!trigger.equals(TRIGGER_NONE)) {
72                             triggerChannel(channel.getUID(), trigger);
73                         }
74                     } catch (WlanThermoUnknownChannelException e1) {
75                         logger.debug("{}", e.getMessage());
76                     }
77                 }
78             }
79         } catch (WlanThermoException ignore) {
80             // Nothing more to do
81         } catch (InterruptedException e) {
82             logger.debug("Update interrupted. {}", e.getMessage());
83         }
84     }
85 }