Skip to content

Commit 71d335d

Browse files
authored
[solarforecast] Initial contribution (openhab#13308)
Signed-off-by: Bernd Weymann <[email protected]>
1 parent 4d7864b commit 71d335d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+9205
-0
lines changed

bom/openhab-addons/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,11 @@
16411641
<artifactId>org.openhab.binding.solaredge</artifactId>
16421642
<version>${project.version}</version>
16431643
</dependency>
1644+
<dependency>
1645+
<groupId>org.openhab.addons.bundles</groupId>
1646+
<artifactId>org.openhab.binding.solarforecast</artifactId>
1647+
<version>${project.version}</version>
1648+
</dependency>
16441649
<dependency>
16451650
<groupId>org.openhab.addons.bundles</groupId>
16461651
<artifactId>org.openhab.binding.solarlog</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This content is produced and maintained by the openHAB project.
2+
3+
* Project home: https://www.openhab.org
4+
5+
== Declared Project Licenses
6+
7+
This program and the accompanying materials are made available under the terms
8+
of the Eclipse Public License 2.0 which is available at
9+
https://www.eclipse.org/legal/epl-2.0/.
10+
11+
== Source Code
12+
13+
https://github.com/openhab/openhab-addons

bundles/org.openhab.binding.solarforecast/README.md

+356
Large diffs are not rendered by default.
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.openhab.addons.bundles</groupId>
9+
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
10+
<version>4.2.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>org.openhab.binding.solarforecast</artifactId>
14+
15+
<name>openHAB Add-ons :: Bundles :: SolarForecast Binding</name>
16+
<dependencies>
17+
<!-- version needs to match with other projects like org.openhab.io.openhabcloud.pom.xml -->
18+
<dependency>
19+
<groupId>org.json</groupId>
20+
<artifactId>json</artifactId>
21+
<version>20231013</version>
22+
<scope>compile</scope>
23+
</dependency>
24+
</dependencies>
25+
26+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<features name="org.openhab.binding.solarforecast-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
3+
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
4+
5+
<feature name="openhab-binding-solarforecast" description="SolarForecast Binding" version="${project.version}">
6+
<feature>openhab-runtime-base</feature>
7+
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.solarforecast/${project.version}</bundle>
8+
</feature>
9+
</features>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright (c) 2010-2024 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.solarforecast.internal;
14+
15+
import java.util.Set;
16+
17+
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.openhab.core.thing.ThingTypeUID;
19+
20+
/**
21+
* The {@link SolarForecastBindingConstants} class defines common constants, which are
22+
* used across the whole binding.
23+
*
24+
* @author Bernd Weymann - Initial contribution
25+
*/
26+
@NonNullByDefault
27+
public class SolarForecastBindingConstants {
28+
29+
private static final String BINDING_ID = "solarforecast";
30+
31+
// Things
32+
public static final ThingTypeUID FORECAST_SOLAR_SITE = new ThingTypeUID(BINDING_ID, "fs-site");
33+
public static final ThingTypeUID FORECAST_SOLAR_PLANE = new ThingTypeUID(BINDING_ID, "fs-plane");
34+
public static final ThingTypeUID SOLCAST_SITE = new ThingTypeUID(BINDING_ID, "sc-site");
35+
public static final ThingTypeUID SOLCAST_PLANE = new ThingTypeUID(BINDING_ID, "sc-plane");
36+
public static final Set<ThingTypeUID> SUPPORTED_THING_SET = Set.of(FORECAST_SOLAR_SITE, FORECAST_SOLAR_PLANE,
37+
SOLCAST_SITE, SOLCAST_PLANE);
38+
39+
// Channel groups
40+
public static final String GROUP_AVERAGE = "average";
41+
public static final String GROUP_OPTIMISTIC = "optimistic";
42+
public static final String GROUP_PESSIMISTIC = "pessimistic";
43+
public static final String GROUP_RAW = "raw";
44+
45+
// Channels
46+
public static final String CHANNEL_POWER_ESTIMATE = "power-estimate";
47+
public static final String CHANNEL_ENERGY_ESTIMATE = "energy-estimate";
48+
public static final String CHANNEL_POWER_ACTUAL = "power-actual";
49+
public static final String CHANNEL_ENERGY_ACTUAL = "energy-actual";
50+
public static final String CHANNEL_ENERGY_REMAIN = "energy-remain";
51+
public static final String CHANNEL_ENERGY_TODAY = "energy-today";
52+
public static final String CHANNEL_JSON = "json";
53+
54+
// Other
55+
public static final int REFRESH_ACTUAL_INTERVAL = 1;
56+
public static final String SLASH = "/";
57+
public static final String EMPTY = "";
58+
public static final String PATTERN_FORMAT = "yyyy-MM-dd HH:mm:ss";
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2010-2024 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.solarforecast.internal;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
import org.openhab.binding.solarforecast.internal.actions.SolarForecast;
17+
18+
/**
19+
* The {@link SolarForecastException} is thrown if forecast data is invalid
20+
*
21+
* @author Bernd Weymann - Initial contribution
22+
*/
23+
@NonNullByDefault
24+
@SuppressWarnings("serial")
25+
public class SolarForecastException extends RuntimeException {
26+
27+
public SolarForecastException(SolarForecast ref, String message) {
28+
super(ref.getIdentifier() + " # " + message);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright (c) 2010-2024 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.solarforecast.internal;
14+
15+
import static org.openhab.binding.solarforecast.internal.SolarForecastBindingConstants.*;
16+
17+
import java.util.Optional;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.eclipse.jdt.annotation.Nullable;
21+
import org.eclipse.jetty.client.HttpClient;
22+
import org.openhab.binding.solarforecast.internal.forecastsolar.handler.ForecastSolarBridgeHandler;
23+
import org.openhab.binding.solarforecast.internal.forecastsolar.handler.ForecastSolarPlaneHandler;
24+
import org.openhab.binding.solarforecast.internal.solcast.handler.SolcastBridgeHandler;
25+
import org.openhab.binding.solarforecast.internal.solcast.handler.SolcastPlaneHandler;
26+
import org.openhab.core.i18n.LocationProvider;
27+
import org.openhab.core.i18n.TimeZoneProvider;
28+
import org.openhab.core.io.net.http.HttpClientFactory;
29+
import org.openhab.core.library.types.PointType;
30+
import org.openhab.core.thing.Bridge;
31+
import org.openhab.core.thing.Thing;
32+
import org.openhab.core.thing.ThingTypeUID;
33+
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
34+
import org.openhab.core.thing.binding.ThingHandler;
35+
import org.openhab.core.thing.binding.ThingHandlerFactory;
36+
import org.osgi.service.component.annotations.Activate;
37+
import org.osgi.service.component.annotations.Component;
38+
import org.osgi.service.component.annotations.Reference;
39+
40+
/**
41+
* The {@link SolarForecastHandlerFactory} is responsible for creating things and thing
42+
* handlers.
43+
*
44+
* @author Bernd Weymann - Initial contribution
45+
*/
46+
@NonNullByDefault
47+
@Component(configurationPid = "binding.solarforecast", service = ThingHandlerFactory.class)
48+
public class SolarForecastHandlerFactory extends BaseThingHandlerFactory {
49+
private final TimeZoneProvider timeZoneProvider;
50+
private final HttpClient httpClient;
51+
private Optional<PointType> location = Optional.empty();
52+
53+
@Activate
54+
public SolarForecastHandlerFactory(final @Reference HttpClientFactory hcf, final @Reference LocationProvider lp,
55+
final @Reference TimeZoneProvider tzp) {
56+
timeZoneProvider = tzp;
57+
httpClient = hcf.getCommonHttpClient();
58+
PointType pt = lp.getLocation();
59+
if (pt != null) {
60+
location = Optional.of(pt);
61+
}
62+
}
63+
64+
@Override
65+
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
66+
return SolarForecastBindingConstants.SUPPORTED_THING_SET.contains(thingTypeUID);
67+
}
68+
69+
@Override
70+
protected @Nullable ThingHandler createHandler(Thing thing) {
71+
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
72+
if (FORECAST_SOLAR_SITE.equals(thingTypeUID)) {
73+
return new ForecastSolarBridgeHandler((Bridge) thing, location);
74+
} else if (FORECAST_SOLAR_PLANE.equals(thingTypeUID)) {
75+
return new ForecastSolarPlaneHandler(thing, httpClient);
76+
} else if (SOLCAST_SITE.equals(thingTypeUID)) {
77+
return new SolcastBridgeHandler((Bridge) thing, timeZoneProvider);
78+
} else if (SOLCAST_PLANE.equals(thingTypeUID)) {
79+
return new SolcastPlaneHandler(thing, httpClient);
80+
}
81+
return null;
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* Copyright (c) 2010-2024 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.solarforecast.internal.actions;
14+
15+
import java.time.Instant;
16+
import java.time.LocalDate;
17+
18+
import javax.measure.quantity.Energy;
19+
import javax.measure.quantity.Power;
20+
21+
import org.eclipse.jdt.annotation.NonNullByDefault;
22+
import org.openhab.binding.solarforecast.internal.solcast.SolcastObject.QueryMode;
23+
import org.openhab.core.library.types.QuantityType;
24+
import org.openhab.core.types.TimeSeries;
25+
26+
/**
27+
* The {@link SolarForecast} Interface needed for Actions
28+
*
29+
* @author Bernd Weymann - Initial contribution
30+
*/
31+
@NonNullByDefault
32+
public interface SolarForecast {
33+
/**
34+
* Argument can be used to query an average forecast scenario
35+
*/
36+
public static final String AVERAGE = "average";
37+
/**
38+
* Argument can be used to query an optimistic forecast scenario
39+
*/
40+
public static final String OPTIMISTIC = "optimistic";
41+
/**
42+
* Argument can be used to query a pessimistic forecast scenario
43+
*/
44+
public static final String PESSIMISTIC = "pessimistic";
45+
46+
/**
47+
* Returns electric energy production for one day
48+
*
49+
* @param date
50+
* @param args possible arguments from this interface
51+
* @return QuantityType<Energy> in kW/h
52+
*/
53+
QuantityType<Energy> getDay(LocalDate date, String... args);
54+
55+
/**
56+
* Returns electric energy between two timestamps
57+
*
58+
* @param start
59+
* @param end
60+
* @param args possible arguments from this interface
61+
* @return QuantityType<Energy> in kW/h
62+
*/
63+
QuantityType<Energy> getEnergy(Instant start, Instant end, String... args);
64+
65+
/**
66+
* Returns electric power at one specific point of time
67+
*
68+
* @param timestamp
69+
* @param args possible arguments from this interface
70+
* @return QuantityType<Power> in kW
71+
*/
72+
QuantityType<Power> getPower(Instant timestamp, String... args);
73+
74+
/**
75+
* Get the first date and time of forecast data
76+
*
77+
* @return date time
78+
*/
79+
Instant getForecastBegin();
80+
81+
/**
82+
* Get the last date and time of forecast data
83+
*
84+
* @return date time
85+
*/
86+
Instant getForecastEnd();
87+
88+
/**
89+
* Get TimeSeries for Power forecast
90+
*
91+
* @param mode QueryMode for optimistic, pessimistic or average estimation
92+
* @return TimeSeries containing QuantityType<Power>
93+
*/
94+
TimeSeries getPowerTimeSeries(QueryMode mode);
95+
96+
/**
97+
* Get TimeSeries for Energy forecast
98+
*
99+
* @param mode QueryMode for optimistic, pessimistic or average estimation
100+
* @return TimeSeries containing QuantityType<Energy>
101+
*/
102+
TimeSeries getEnergyTimeSeries(QueryMode mode);
103+
104+
/**
105+
* SolarForecast identifier
106+
*
107+
* @return unique String to identify solar plane
108+
*/
109+
String getIdentifier();
110+
}

0 commit comments

Comments
 (0)