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.wled.internal.api;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jetty.client.HttpClient;
17 import org.openhab.binding.wled.internal.handlers.WLedBridgeHandler;
18 import org.openhab.core.io.net.http.HttpClientFactory;
19 import org.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Reference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * The {@link WledApiFactory} is responsible for creating an instance of the API that is optimized for different
29 * @author Matthew Skinner - Initial contribution
31 @Component(service = WledApiFactory.class)
33 public class WledApiFactory {
34 private final Logger logger = LoggerFactory.getLogger(this.getClass());
35 private final HttpClient httpClient;
38 public WledApiFactory(@Reference HttpClientFactory httpClientFactory) {
39 this.httpClient = httpClientFactory.getCommonHttpClient();
42 public WledApi getApi(WLedBridgeHandler handler) throws ApiException {
43 WledApi lowestSupportedApi = new WledApiV084(handler, httpClient);
44 int version = lowestSupportedApi.getFirmwareVersion();
45 logger.debug("Treating firmware as int:{}", version);
47 return new WledApiV0130(handler, httpClient);
48 } else if (version >= 110) {
49 return new WledApiV0110(handler, httpClient);
50 } else if (version >= 100) {
51 return new WledApiV084(handler, httpClient);
53 logger.warn("Your WLED firmware is very old, upgrade to at least 0.10.0");
54 return lowestSupportedApi;