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.mybmw.internal;
15 import static org.openhab.binding.mybmw.internal.MyBMWConstants.*;
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.i18n.LocationProvider;
24 import org.openhab.core.io.net.http.HttpClientFactory;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
36 * The {@link MyBMWHandlerFactory} is responsible for creating things and thing
39 * @author Bernd Weymann - Initial contribution
42 @Component(configurationPid = "binding.mybmw", service = ThingHandlerFactory.class)
43 public class MyBMWHandlerFactory extends BaseThingHandlerFactory {
44 private final HttpClientFactory httpClientFactory;
45 private final MyBMWCommandOptionProvider commandOptionProvider;
46 private final LocationProvider locationProvider;
47 private String localeLanguage;
50 public MyBMWHandlerFactory(final @Reference HttpClientFactory hcf, final @Reference MyBMWCommandOptionProvider cop,
51 final @Reference LocaleProvider localeP, final @Reference LocationProvider locationP) {
52 httpClientFactory = hcf;
53 commandOptionProvider = cop;
54 locationProvider = locationP;
55 localeLanguage = localeP.getLocale().getLanguage().toLowerCase();
59 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
60 return SUPPORTED_THING_SET.contains(thingTypeUID);
64 protected @Nullable ThingHandler createHandler(Thing thing) {
65 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
66 if (THING_TYPE_CONNECTED_DRIVE_ACCOUNT.equals(thingTypeUID)) {
67 return new MyBMWBridgeHandler((Bridge) thing, httpClientFactory, localeLanguage);
68 } else if (SUPPORTED_THING_SET.contains(thingTypeUID)) {
69 return new VehicleHandler(thing, commandOptionProvider, locationProvider, thingTypeUID.getId());