2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.wlanthermo.internal.api.mini;
15 import static org.openhab.binding.wlanthermo.internal.WlanThermoBindingConstants.TRIGGER_NONE;
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;
26 * The {@link WlanThermoMiniHandler} is responsible for handling commands, which are
27 * sent to one of the channels.
29 * @author Christian Schlipp - Initial contribution
32 public class WlanThermoMiniHandler extends WlanThermoHandler {
34 private App app = new App();
36 public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) {
37 super(thing, httpClient, false);
41 protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException {
42 return WlanThermoMiniCommandHandler.getState(channelUID, app);
46 protected boolean setState(ChannelUID channelUID, Command command) {
52 protected void push() {
53 // Unused, Mini is read-only!
57 protected void pull() {
59 // Update objects with data from device
60 app = doGet("/app.php", App.class);
63 for (Channel channel : thing.getChannels()) {
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
70 String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app);
71 if (!trigger.equals(TRIGGER_NONE)) {
72 triggerChannel(channel.getUID(), trigger);
74 } catch (WlanThermoUnknownChannelException e1) {
75 logger.debug("{}", e.getMessage());
79 } catch (WlanThermoException ignore) {
81 } catch (InterruptedException e) {
82 logger.debug("Update interrupted. {}", e.getMessage());