2 * Copyright (c) 2010-2024 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.meteostick.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.meteostick.internal.handler.MeteostickBridgeHandler;
18 import org.openhab.binding.meteostick.internal.handler.MeteostickSensorHandler;
19 import org.openhab.core.io.transport.serial.SerialPortManager;
20 import org.openhab.core.thing.Bridge;
21 import org.openhab.core.thing.Thing;
22 import org.openhab.core.thing.ThingTypeUID;
23 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
24 import org.openhab.core.thing.binding.ThingHandler;
25 import org.openhab.core.thing.binding.ThingHandlerFactory;
26 import org.osgi.service.component.annotations.Activate;
27 import org.osgi.service.component.annotations.Component;
28 import org.osgi.service.component.annotations.Reference;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link MeteostickHandlerFactory} is responsible for creating things and thing
36 * @author Chris Jackson - Initial contribution
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.meteostick")
40 public class MeteostickHandlerFactory extends BaseThingHandlerFactory {
41 private Logger logger = LoggerFactory.getLogger(MeteostickHandlerFactory.class);
43 private final SerialPortManager serialPortManager;
46 public MeteostickHandlerFactory(final @Reference SerialPortManager serialPortManager) {
47 this.serialPortManager = serialPortManager;
51 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
52 return MeteostickBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
53 | MeteostickSensorHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID);
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 logger.debug("MeteoStick thing factory: createHandler {} of type {}", thing.getThingTypeUID(), thing.getUID());
60 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
62 if (MeteostickBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
63 return new MeteostickBridgeHandler((Bridge) thing, serialPortManager);
66 if (MeteostickSensorHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
67 return new MeteostickSensorHandler(thing);