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.solaredge.internal.handler;
15 import java.util.ArrayList;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.solaredge.internal.command.AggregateDataUpdatePrivateApi;
20 import org.openhab.binding.solaredge.internal.command.AggregateDataUpdatePublicApi;
21 import org.openhab.binding.solaredge.internal.command.SolarEdgeCommand;
22 import org.openhab.binding.solaredge.internal.model.AggregatePeriod;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Polling worker class. This is responsible for periodic polling of sensor data.
29 * @author Alexander Friese - initial contribution
32 public class SolarEdgeAggregateDataPolling implements Runnable {
36 private final Logger logger = LoggerFactory.getLogger(getClass());
39 * Handler for delegation to callbacks.
41 private final SolarEdgeHandler handler;
46 * @param handler handler which handles results of polling
48 public SolarEdgeAggregateDataPolling(SolarEdgeHandler handler) {
49 this.handler = handler;
53 * Poll the SolarEdge Webservice one time per call.
57 // if no meter is present all data will be fetched by the 'LiveDataUpdateMeterless'
58 if (handler.getConfiguration().isMeterInstalled()) {
59 logger.debug("polling SolarEdge aggregate data {}", handler.getConfiguration());
61 List<SolarEdgeCommand> commands = new ArrayList<>();
63 if (handler.getConfiguration().isUsePrivateApi()) {
64 commands.add(new AggregateDataUpdatePrivateApi(handler, AggregatePeriod.DAY));
65 commands.add(new AggregateDataUpdatePrivateApi(handler, AggregatePeriod.WEEK));
66 commands.add(new AggregateDataUpdatePrivateApi(handler, AggregatePeriod.MONTH));
67 commands.add(new AggregateDataUpdatePrivateApi(handler, AggregatePeriod.YEAR));
69 commands.add(new AggregateDataUpdatePublicApi(handler, AggregatePeriod.DAY));
70 commands.add(new AggregateDataUpdatePublicApi(handler, AggregatePeriod.WEEK));
71 commands.add(new AggregateDataUpdatePublicApi(handler, AggregatePeriod.MONTH));
72 commands.add(new AggregateDataUpdatePublicApi(handler, AggregatePeriod.YEAR));
75 for (SolarEdgeCommand command : commands) {
76 handler.getWebInterface().enqueueCommand(command);