]> git.basschouten.com Git - openhab-addons.git/blob
bbcd5d972934645032c7a16d74d2c390f30b6f61
[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.io.hueemulation.internal;
14
15 import java.io.IOException;
16 import java.util.Dictionary;
17 import java.util.Hashtable;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.osgi.service.cm.Configuration;
21 import org.osgi.service.cm.ConfigurationAdmin;
22
23 /**
24  * Find all configuration admin interactions in this class
25  *
26  * @author David Graeff - Initial contribution
27  */
28 @NonNullByDefault
29 public class WriteConfig {
30     public static void setUUID(ConfigurationAdmin configAdmin, String uuid) {
31         try {
32             Configuration configuration = configAdmin.getConfiguration(HueEmulationService.CONFIG_PID, null);
33             Dictionary<String, Object> dictionary = configuration.getProperties();
34             if (dictionary == null) {
35                 dictionary = new Hashtable<>();
36             }
37             dictionary.put(HueEmulationConfig.CONFIG_UUID, uuid);
38             configuration.update(dictionary); // This will restart the service (and call activate again)
39         } catch (IOException e) {
40             throw new IllegalArgumentException(e);
41         }
42     }
43
44     /**
45      * Persists the link mode off state
46      */
47     public static void unsetPairingMode(ConfigurationAdmin configAdmin) {
48         try {
49             org.osgi.service.cm.Configuration configuration = configAdmin
50                     .getConfiguration(HueEmulationService.CONFIG_PID, null);
51             Dictionary<String, Object> dictionary = configuration.getProperties();
52             dictionary.put(HueEmulationConfig.CONFIG_PAIRING_ENABLED, false);
53             dictionary.put(HueEmulationConfig.CONFIG_CREATE_NEW_USER_ON_THE_FLY, false);
54             dictionary.put(HueEmulationConfig.CONFIG_EMULATE_V1, false);
55             configuration.update(dictionary);
56         } catch (IOException ignore) {
57         }
58     }
59 }