2 * Copyright (c) 2010-2020 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.hydrawise.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jetty.client.HttpClient;
17 import org.openhab.binding.hydrawise.internal.api.HydrawiseAuthenticationException;
18 import org.openhab.binding.hydrawise.internal.api.HydrawiseCommandException;
19 import org.openhab.binding.hydrawise.internal.api.HydrawiseConnectionException;
20 import org.openhab.binding.hydrawise.internal.api.HydrawiseLocalApiClient;
21 import org.openhab.binding.hydrawise.internal.api.model.Relay;
22 import org.openhab.core.thing.Thing;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The {@link HydrawiseLocalHandler} is responsible for handling commands, which are
28 * sent to one of the channels.
30 * @author Dan Cunningham - Initial contribution
33 public class HydrawiseLocalHandler extends HydrawiseHandler {
34 private final Logger logger = LoggerFactory.getLogger(HydrawiseLocalHandler.class);
35 HydrawiseLocalApiClient client;
37 public HydrawiseLocalHandler(Thing thing, HttpClient httpClient) {
39 client = new HydrawiseLocalApiClient(httpClient);
43 protected void configure() throws HydrawiseConnectionException, HydrawiseAuthenticationException {
44 HydrawiseLocalConfiguration configuration = getConfig().as(HydrawiseLocalConfiguration.class);
45 this.refresh = Math.max(configuration.refresh, MIN_REFRESH_SECONDS);
46 logger.trace("Connecting to host {}", configuration.host);
47 client.setCredentials(configuration.host, configuration.username, configuration.password);
52 protected void pollController() throws HydrawiseConnectionException, HydrawiseAuthenticationException {
53 updateZones(client.getLocalSchedule());
57 protected void sendRunCommand(int seconds, Relay relay)
58 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
59 client.runRelay(seconds, relay.relay);
63 protected void sendRunCommand(Relay relay)
64 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
65 client.runRelay(relay.relay);
69 protected void sendStopCommand(Relay relay)
70 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
71 client.stopRelay(relay.relay);
75 protected void sendRunAllCommand()
76 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
77 client.runAllRelays();
81 protected void sendRunAllCommand(int seconds)
82 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
83 client.runAllRelays(seconds);
87 protected void sendStopAllCommand()
88 throws HydrawiseCommandException, HydrawiseConnectionException, HydrawiseAuthenticationException {
89 client.stopAllRelays();