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.yeelight.internal.lib.device;
15 import java.util.HashMap;
18 import org.openhab.binding.yeelight.internal.lib.enums.DeviceType;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * The {@link DeviceFactory} creates device handler classes.
25 * @author Coaster Li - Initial contribution
26 * @author Nikita Pogudalov - Added CeilingDeviceWithNightDevice for Ceiling 1
28 public class DeviceFactory {
29 private static final Logger LOGGER = LoggerFactory.getLogger(DeviceFactory.class);
31 private static final String TAG = DeviceFactory.class.getSimpleName();
33 public static DeviceBase build(String model, String id) {
34 DeviceType type = DeviceType.valueOf(model);
37 return new CeilingDevice(id);
42 return new CeilingDeviceWithNightDevice(id);
44 return new CeilingDeviceWithAmbientDevice(id);
47 return new WonderDevice(id);
49 return new MonoDevice(id);
51 return new CtBulbDevice(id);
54 return new PitayaDevice(id);
56 return new DesklampDevice(id);
62 public static DeviceBase build(Map<String, String> bulbInfo) {
63 DeviceBase device = build(bulbInfo.get("model"), bulbInfo.get("id"));
68 Map<String, Object> infos = new HashMap<>(bulbInfo);
69 device.setBulbInfo(infos);
70 LOGGER.debug("{}: DeviceFactory Device = {}", TAG, bulbInfo.get("Location"));
71 // TODO enhancement!!!
72 String[] addressInfo = bulbInfo.get("Location").split(":");
73 device.setAddress(addressInfo[1].substring(2));
74 device.setPort(Integer.parseInt(addressInfo[2]));
75 device.setOnline(true);
76 LOGGER.debug("{}: DeviceFactory Device info = {}, port = {}", TAG, device.getAddress(), device.getPort());