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.io.hueemulation.internal;
15 import java.io.IOException;
16 import java.util.Dictionary;
17 import java.util.Hashtable;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.osgi.service.cm.Configuration;
21 import org.osgi.service.cm.ConfigurationAdmin;
24 * Find all configuration admin interactions in this class
26 * @author David Graeff - Initial contribution
29 public class WriteConfig {
30 public static void setUUID(ConfigurationAdmin configAdmin, String uuid) {
32 Configuration configuration = configAdmin.getConfiguration(HueEmulationService.CONFIG_PID, null);
33 Dictionary<String, Object> dictionary = configuration.getProperties();
34 if (dictionary == null) {
35 dictionary = new Hashtable<>();
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);
45 * Persists the link mode off state
47 public static void unsetPairingMode(ConfigurationAdmin configAdmin) {
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) {