]> git.basschouten.com Git - openhab-addons.git/blob
b2a9e2821c37719f8280eba1c7e698c3f31a0ce3
[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.opensprinkler.internal.api;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jetty.client.HttpClient;
17 import org.openhab.binding.opensprinkler.internal.api.exception.CommunicationApiException;
18 import org.openhab.binding.opensprinkler.internal.api.exception.GeneralApiException;
19 import org.openhab.binding.opensprinkler.internal.api.exception.UnauthorizedApiException;
20 import org.openhab.binding.opensprinkler.internal.config.OpenSprinklerHttpInterfaceConfig;
21
22 /**
23  * The {@link OpenSprinklerHttpApiV219} class is used for communicating with
24  * the firmware versions 2.1.9
25  *
26  * @author Matthew Skinner - Initial contribution
27  */
28 @NonNullByDefault
29 public class OpenSprinklerHttpApiV219 extends OpenSprinklerHttpApiV217 {
30
31     OpenSprinklerHttpApiV219(final HttpClient httpClient, final OpenSprinklerHttpInterfaceConfig config)
32             throws GeneralApiException, CommunicationApiException {
33         super(httpClient, config);
34     }
35
36     @Override
37     public void ignoreRain(int station, boolean command) throws CommunicationApiException, UnauthorizedApiException {
38         int arrayIndex = station / 8;
39         int bit = station % 8;
40         logger.debug("Ignore Rain for Station:{} is being looked in index: {} and bit:{}", station, arrayIndex, bit);
41         byte status = state.jnReply.ignoreRain[arrayIndex];
42         if (command) {
43             status |= 1 << bit;
44         } else {
45             status &= ~(1 << bit);
46         }
47         http.sendHttpGet(getBaseUrl() + "cs", getRequestRequiredOptions() + "&i" + arrayIndex + "=" + status);
48     }
49
50     @Override
51     public boolean isIgnoringRain(int station) {
52         int arrayIndex = station / 8;
53         int bit = station % 8;
54         byte status = state.jnReply.ignoreRain[arrayIndex];
55         return (status & (1 << bit)) != 0;
56     }
57 }