]> git.basschouten.com Git - openhab-addons.git/blob
cde55cec069b4ae8821dc1c9224cb7b506277b23
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.fineoffsetweatherstation.internal;
14
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;
18
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;
37
38 /**
39  * The {@link FineOffsetWeatherStationHandlerFactory} is responsible for creating things and thing
40  * handlers.
41  *
42  * @author Andreas Berger - Initial contribution
43  */
44 @NonNullByDefault
45 @Component(configurationPid = "binding.fineoffsetweatherstation", service = ThingHandlerFactory.class)
46 public class FineOffsetWeatherStationHandlerFactory extends BaseThingHandlerFactory {
47
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;
53
54     @Activate
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;
63     }
64
65     @Override
66     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68     }
69
70     @Override
71     protected @Nullable ThingHandler createHandler(Thing thing) {
72         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
73
74         if (THING_TYPE_GATEWAY.equals(thingTypeUID) && thing instanceof Bridge bridge) {
75             return new FineOffsetGatewayHandler(bridge, gatewayDiscoveryService, channelTypeRegistry,
76                     translationProvider, localeProvider, timeZoneProvider);
77         }
78         if (THING_TYPE_SENSOR.equals(thingTypeUID)) {
79             return new FineOffsetSensorHandler(thing);
80         }
81
82         return null;
83     }
84 }