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.fineoffsetweatherstation.internal;
15 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.SUPPORTED_THING_TYPES_UIDS;
16 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.THING_TYPE_GATEWAY;
17 import static org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants.THING_TYPE_SENSOR;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.fineoffsetweatherstation.internal.discovery.FineOffsetGatewayDiscoveryService;
22 import org.openhab.binding.fineoffsetweatherstation.internal.handler.FineOffsetGatewayHandler;
23 import org.openhab.binding.fineoffsetweatherstation.internal.handler.FineOffsetSensorHandler;
24 import org.openhab.core.i18n.LocaleProvider;
25 import org.openhab.core.i18n.TimeZoneProvider;
26 import org.openhab.core.i18n.TranslationProvider;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.openhab.core.thing.type.ChannelTypeRegistry;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
39 * The {@link FineOffsetWeatherStationHandlerFactory} is responsible for creating things and thing
42 * @author Andreas Berger - Initial contribution
45 @Component(configurationPid = "binding.fineoffsetweatherstation", service = ThingHandlerFactory.class)
46 public class FineOffsetWeatherStationHandlerFactory extends BaseThingHandlerFactory {
48 private final FineOffsetGatewayDiscoveryService gatewayDiscoveryService;
49 private final ChannelTypeRegistry channelTypeRegistry;
50 private final TranslationProvider translationProvider;
51 private final LocaleProvider localeProvider;
52 private final TimeZoneProvider timeZoneProvider;
55 public FineOffsetWeatherStationHandlerFactory(@Reference FineOffsetGatewayDiscoveryService gatewayDiscoveryService,
56 @Reference ChannelTypeRegistry channelTypeRegistry, @Reference TranslationProvider translationProvider,
57 @Reference LocaleProvider localeProvider, @Reference TimeZoneProvider timeZoneProvider) {
58 this.gatewayDiscoveryService = gatewayDiscoveryService;
59 this.channelTypeRegistry = channelTypeRegistry;
60 this.translationProvider = translationProvider;
61 this.localeProvider = localeProvider;
62 this.timeZoneProvider = timeZoneProvider;
66 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
71 protected @Nullable ThingHandler createHandler(Thing thing) {
72 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
74 if (THING_TYPE_GATEWAY.equals(thingTypeUID) && thing instanceof Bridge) {
75 return new FineOffsetGatewayHandler((Bridge) thing, gatewayDiscoveryService, channelTypeRegistry,
76 translationProvider, localeProvider, timeZoneProvider);
78 if (THING_TYPE_SENSOR.equals(thingTypeUID)) {
79 return new FineOffsetSensorHandler(thing);