]> git.basschouten.com Git - openhab-addons.git/blob
f4d5180f25c4ddb39f210bc9a1544045f8ca2b00
[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.solaredge.internal.handler;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.solaredge.internal.command.LiveDataUpdateMeterless;
17 import org.openhab.binding.solaredge.internal.command.LiveDataUpdatePrivateApi;
18 import org.openhab.binding.solaredge.internal.command.LiveDataUpdatePublicApi;
19 import org.openhab.binding.solaredge.internal.command.SolarEdgeCommand;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Polling worker class. This is responsible for periodic polling of sensor data.
25  *
26  * @author Alexander Friese - initial contribution
27  */
28 @NonNullByDefault
29 public class SolarEdgeLiveDataPolling implements Runnable {
30     /**
31      * Logger
32      */
33     private final Logger logger = LoggerFactory.getLogger(getClass());
34
35     /**
36      * Handler for delegation to callbacks.
37      */
38     private final SolarEdgeHandler handler;
39
40     /**
41      * Constructor.
42      *
43      * @param handler handler which handles results of polling
44      */
45     public SolarEdgeLiveDataPolling(SolarEdgeHandler handler) {
46         this.handler = handler;
47     }
48
49     /**
50      * Poll the SolarEdge Webservice one time per call.
51      */
52     @Override
53     public void run() {
54         logger.debug("polling SolarEdge live data {}", handler.getConfiguration());
55
56         SolarEdgeCommand ldu;
57
58         if (handler.getConfiguration().isUsePrivateApi()) {
59             ldu = new LiveDataUpdatePrivateApi(handler);
60         } else {
61             if (handler.getConfiguration().isMeterInstalled()) {
62                 ldu = new LiveDataUpdatePublicApi(handler);
63             } else {
64                 ldu = new LiveDataUpdateMeterless(handler);
65             }
66         }
67
68         handler.getWebInterface().enqueueCommand(ldu);
69     }
70 }