2 * Copyright (c) 2010-2024 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.solarforecast.internal;
15 import static org.openhab.binding.solarforecast.internal.SolarForecastBindingConstants.*;
17 import java.util.Optional;
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;
41 * The {@link SolarForecastHandlerFactory} is responsible for creating things and thing
44 * @author Bernd Weymann - Initial contribution
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();
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();
60 location = Optional.of(pt);
65 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
66 return SolarForecastBindingConstants.SUPPORTED_THING_SET.contains(thingTypeUID);
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);