]> git.basschouten.com Git - openhab-addons.git/blob
3d585a7247877537a1853ae7eb7596799baaa07b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.vizio.internal.appdb;
14
15 import static org.openhab.binding.vizio.internal.VizioBindingConstants.*;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.nio.charset.StandardCharsets;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.osgi.service.component.annotations.Activate;
23 import org.osgi.service.component.annotations.Component;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {@link VizioAppDbService} class makes available a JSON list of known apps on Vizio TVs.
29  *
30  * @author Michael Lobstein - Initial Contribution
31  */
32
33 @Component(service = VizioAppDbService.class)
34 @NonNullByDefault
35 public class VizioAppDbService {
36     private final Logger logger = LoggerFactory.getLogger(VizioAppDbService.class);
37     private String vizioAppsJson;
38
39     @Activate
40     public VizioAppDbService() {
41         try {
42             InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("/db/apps.json");
43             if (is != null) {
44                 vizioAppsJson = new String(is.readAllBytes(), StandardCharsets.UTF_8);
45             } else {
46                 vizioAppsJson = EMPTY;
47             }
48         } catch (IOException e) {
49             logger.warn("Unable to load Vizio app list : {}", e.getMessage());
50             vizioAppsJson = EMPTY;
51         }
52     }
53
54     public String getVizioAppsJson() {
55         return vizioAppsJson;
56     }
57 }