]> git.basschouten.com Git - openhab-addons.git/blob
902d51e069ff8f8e0c3db30b221ab2ceb317f44d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.mybmw.internal;
14
15 import static org.openhab.binding.mybmw.internal.MyBMWConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.mybmw.internal.handler.MyBMWBridgeHandler;
20 import org.openhab.binding.mybmw.internal.handler.MyBMWCommandOptionProvider;
21 import org.openhab.binding.mybmw.internal.handler.VehicleHandler;
22 import org.openhab.core.i18n.LocaleProvider;
23 import org.openhab.core.io.net.http.HttpClientFactory;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
28 import org.openhab.core.thing.binding.ThingHandler;
29 import org.openhab.core.thing.binding.ThingHandlerFactory;
30 import org.osgi.service.component.annotations.Activate;
31 import org.osgi.service.component.annotations.Component;
32 import org.osgi.service.component.annotations.Reference;
33
34 /**
35  * The {@link MyBMWHandlerFactory} is responsible for creating things and thing
36  * handlers.
37  *
38  * @author Bernd Weymann - Initial contribution
39  */
40 @NonNullByDefault
41 @Component(configurationPid = "binding.mybmw", service = ThingHandlerFactory.class)
42 public class MyBMWHandlerFactory extends BaseThingHandlerFactory {
43     private final HttpClientFactory httpClientFactory;
44     private final MyBMWCommandOptionProvider commandOptionProvider;
45     private String localeLanguage;
46
47     @Activate
48     public MyBMWHandlerFactory(final @Reference HttpClientFactory hcf, final @Reference MyBMWCommandOptionProvider cop,
49             final @Reference LocaleProvider lp) {
50         httpClientFactory = hcf;
51         commandOptionProvider = cop;
52         localeLanguage = lp.getLocale().getLanguage().toLowerCase();
53     }
54
55     @Override
56     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57         return SUPPORTED_THING_SET.contains(thingTypeUID);
58     }
59
60     @Override
61     protected @Nullable ThingHandler createHandler(Thing thing) {
62         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
63         if (THING_TYPE_CONNECTED_DRIVE_ACCOUNT.equals(thingTypeUID)) {
64             return new MyBMWBridgeHandler((Bridge) thing, httpClientFactory, localeLanguage);
65         } else if (SUPPORTED_THING_SET.contains(thingTypeUID)) {
66             VehicleHandler vh = new VehicleHandler(thing, commandOptionProvider, thingTypeUID.getId());
67             return vh;
68         }
69         return null;
70     }
71 }