2 * Copyright (c) 2010-2023 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.WlanThermoException;
20 import org.openhab.binding.wlanthermo.internal.WlanThermoHandler;
21 import org.openhab.binding.wlanthermo.internal.WlanThermoInputException;
22 import org.openhab.binding.wlanthermo.internal.WlanThermoUnknownChannelException;
23 import org.openhab.binding.wlanthermo.internal.api.mini.dto.builtin.App;
24 import org.openhab.core.thing.Channel;
25 import org.openhab.core.thing.ChannelUID;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.State;
31 * The {@link WlanThermoMiniHandler} is responsible for handling commands, which are
32 * sent to one of the channels.
34 * @author Christian Schlipp - Initial contribution
37 public class WlanThermoMiniHandler extends WlanThermoHandler {
39 private App app = new App();
41 public WlanThermoMiniHandler(Thing thing, HttpClient httpClient) {
42 super(thing, httpClient, false);
46 protected State getState(ChannelUID channelUID) throws WlanThermoInputException, WlanThermoUnknownChannelException {
47 return WlanThermoMiniCommandHandler.getState(channelUID, app);
51 protected boolean setState(ChannelUID channelUID, Command command) {
57 protected void push() {
58 // Unused, Mini is read-only!
62 protected void pull() {
64 // Update objects with data from device
65 app = doGet("/app.php", App.class);
68 for (Channel channel : thing.getChannels()) {
70 State state = WlanThermoMiniCommandHandler.getState(channel.getUID(), app);
71 updateState(channel.getUID(), state);
72 } catch (WlanThermoUnknownChannelException e) {
73 // if we could not obtain a state, try trigger instead
75 String trigger = WlanThermoMiniCommandHandler.getTrigger(channel.getUID(), app);
76 if (!trigger.equals(TRIGGER_NONE)) {
77 triggerChannel(channel.getUID(), trigger);
79 } catch (WlanThermoUnknownChannelException e1) {
80 logger.debug("{}", e.getMessage());
84 } catch (WlanThermoException ignore) {
86 } catch (InterruptedException e) {
87 logger.debug("Update interrupted. {}", e.getMessage());