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.broadlinkthermostat.internal;
16 import java.nio.file.Path;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.broadlinkthermostat.internal.handler.FloureonThermostatHandler;
22 import org.openhab.binding.broadlinkthermostat.internal.handler.RMUniversalRemoteHandler;
23 import org.openhab.core.OpenHAB;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link BroadlinkHandlerFactory} is responsible for creating things and thing handlers.
36 * @author Florian Mueller - Initial contribution
38 @Component(configurationPid = "binding.broadlinkthermostat", service = ThingHandlerFactory.class)
40 public class BroadlinkHandlerFactory extends BaseThingHandlerFactory {
41 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(
42 BroadlinkBindingConstants.FLOUREON_THERMOSTAT_THING_TYPE,
43 BroadlinkBindingConstants.RM_UNIVERSAL_REMOTE_THING_TYPE,
44 BroadlinkBindingConstants.HYSEN_THERMOSTAT_THING_TYPE);
45 private static final String BROADLINK_FOLDER = Path.of(OpenHAB.getUserDataFolder(), "broadlink").toString();
46 public static final String INFRARED_FOLDER = Path.of(BROADLINK_FOLDER, "infrared_commands").toString();
48 Logger logger = LoggerFactory.getLogger(BroadlinkHandlerFactory.class);
49 File directory = new File(BROADLINK_FOLDER);
50 if (!directory.exists()) {
51 if (directory.mkdir()) {
52 logger.info("broadlink dir created {}", BROADLINK_FOLDER);
55 File childDirectory = new File(INFRARED_FOLDER);
56 if (!childDirectory.exists()) {
57 if (childDirectory.mkdir()) {
58 logger.info("infrared_commands dir created {}", INFRARED_FOLDER);
64 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
65 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
69 protected @Nullable ThingHandler createHandler(Thing thing) {
70 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
72 if (BroadlinkBindingConstants.FLOUREON_THERMOSTAT_THING_TYPE.equals(thingTypeUID)
73 || BroadlinkBindingConstants.HYSEN_THERMOSTAT_THING_TYPE.equals(thingTypeUID)) {
74 return new FloureonThermostatHandler(thing);
76 if (BroadlinkBindingConstants.RM_UNIVERSAL_REMOTE_THING_TYPE.equals(thingTypeUID)) {
77 return new RMUniversalRemoteHandler(thing);