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.shelly.internal.manager;
15 import static org.openhab.binding.shelly.internal.manager.ShellyManagerConstants.*;
17 import java.util.LinkedHashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.eclipse.jetty.http.HttpStatus;
23 import org.openhab.binding.shelly.internal.ShellyHandlerFactory;
24 import org.openhab.binding.shelly.internal.api.ShellyApiException;
25 import org.openhab.binding.shelly.internal.manager.ShellyManagerPage.ShellyMgrResponse;
26 import org.openhab.binding.shelly.internal.provider.ShellyTranslationProvider;
27 import org.osgi.service.cm.ConfigurationAdmin;
30 * {@link ShellyManager} implements the Shelly Manager
32 * @author Markus Michels - Initial contribution
35 public class ShellyManager {
36 private final Map<String, ShellyManagerPage> pages = new LinkedHashMap<>();
38 public ShellyManager(ConfigurationAdmin configurationAdmin, ShellyTranslationProvider translationProvider,
39 HttpClient httpClient, String localIp, int localPort, ShellyHandlerFactory handlerFactory) {
40 pages.put(SHELLY_MGR_OVERVIEW_URI, new ShellyManagerOverviewPage(configurationAdmin, translationProvider,
41 httpClient, localIp, localPort, handlerFactory));
42 pages.put(SHELLY_MGR_ACTION_URI, new ShellyManagerActionPage(configurationAdmin, translationProvider,
43 httpClient, localIp, localPort, handlerFactory));
44 pages.put(SHELLY_MGR_FWUPDATE_URI, new ShellyManagerOtaPage(configurationAdmin, translationProvider, httpClient,
45 localIp, localPort, handlerFactory));
46 pages.put(SHELLY_MGR_OTA_URI, new ShellyManagerOtaPage(configurationAdmin, translationProvider, httpClient,
47 localIp, localPort, handlerFactory));
48 pages.put(SHELLY_MGR_IMAGES_URI, new ShellyManagerImageLoader(configurationAdmin, translationProvider,
49 httpClient, localIp, localPort, handlerFactory));
50 pages.put(SHELLY_MANAGER_URI, new ShellyManagerOverviewPage(configurationAdmin, translationProvider, httpClient,
51 localIp, localPort, handlerFactory));
54 public ShellyMgrResponse generateContent(String path, Map<String, String[]> parameters) throws ShellyApiException {
55 for (Map.Entry<String, ShellyManagerPage> page : pages.entrySet()) {
56 if (path.toLowerCase().startsWith(page.getKey())) {
57 ShellyManagerPage p = page.getValue();
58 return p.generateContent(path, parameters);
61 return new ShellyMgrResponse("Invalid URL or syntax", HttpStatus.BAD_REQUEST_400);