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.SUPPORTED_THING_SET;
16 import static org.openhab.binding.mybmw.internal.MyBMWConstants.THING_TYPE_CONNECTED_DRIVE_ACCOUNT;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.mybmw.internal.handler.MyBMWBridgeHandler;
21 import org.openhab.binding.mybmw.internal.handler.MyBMWCommandOptionProvider;
22 import org.openhab.binding.mybmw.internal.handler.VehicleHandler;
23 import org.openhab.core.i18n.LocaleProvider;
24 import org.openhab.core.i18n.LocationProvider;
25 import org.openhab.core.i18n.TimeZoneProvider;
26 import org.openhab.core.io.net.http.HttpClientFactory;
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.osgi.service.component.annotations.Activate;
34 import org.osgi.service.component.annotations.Component;
35 import org.osgi.service.component.annotations.Reference;
38 * The {@link MyBMWHandlerFactory} is responsible for creating things and thing
41 * @author Bernd Weymann - Initial contribution
42 * @author Martin Grassl - changed localeProvider handling
45 @Component(configurationPid = "binding.mybmw", service = ThingHandlerFactory.class)
46 public class MyBMWHandlerFactory extends BaseThingHandlerFactory {
47 private final HttpClientFactory httpClientFactory;
48 private final MyBMWCommandOptionProvider commandOptionProvider;
49 private final LocationProvider locationProvider;
50 private final TimeZoneProvider timeZoneProvider;
51 private final LocaleProvider localeProvider;
54 public MyBMWHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
55 final @Reference MyBMWCommandOptionProvider commandOptionProvider,
56 final @Reference LocaleProvider localeProvider, final @Reference LocationProvider locationProvider,
57 final @Reference TimeZoneProvider timeZoneProvider) {
58 this.httpClientFactory = httpClientFactory;
59 this.commandOptionProvider = commandOptionProvider;
60 this.locationProvider = locationProvider;
61 this.timeZoneProvider = timeZoneProvider;
62 this.localeProvider = localeProvider;
66 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67 return SUPPORTED_THING_SET.contains(thingTypeUID);
71 protected @Nullable ThingHandler createHandler(Thing thing) {
72 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
73 if (THING_TYPE_CONNECTED_DRIVE_ACCOUNT.equals(thingTypeUID)) {
74 return new MyBMWBridgeHandler((Bridge) thing, httpClientFactory, localeProvider);
75 } else if (SUPPORTED_THING_SET.contains(thingTypeUID)) {
76 return new VehicleHandler(thing, commandOptionProvider, locationProvider, timeZoneProvider,
77 thingTypeUID.getId());