2 * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal;
15 import static org.openhab.binding.bmwconnecteddrive.internal.ConnectedDriveConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.bmwconnecteddrive.internal.handler.BMWConnectedDriveOptionProvider;
20 import org.openhab.binding.bmwconnecteddrive.internal.handler.ConnectedDriveBridgeHandler;
21 import org.openhab.binding.bmwconnecteddrive.internal.handler.VehicleHandler;
22 import org.openhab.binding.bmwconnecteddrive.internal.utils.Converter;
23 import org.openhab.core.i18n.LocaleProvider;
24 import org.openhab.core.i18n.TimeZoneProvider;
25 import org.openhab.core.io.net.http.HttpClientFactory;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Activate;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
37 * The {@link ConnectedDriveHandlerFactory} is responsible for creating things and thing
40 * @author Bernd Weymann - Initial contribution
43 @Component(configurationPid = "binding.bmwconnecteddrive", service = ThingHandlerFactory.class)
44 public class ConnectedDriveHandlerFactory extends BaseThingHandlerFactory {
46 private final HttpClientFactory httpClientFactory;
47 private final BMWConnectedDriveOptionProvider optionProvider;
48 private boolean imperial = false;
51 public ConnectedDriveHandlerFactory(final @Reference HttpClientFactory hcf,
52 final @Reference BMWConnectedDriveOptionProvider op, final @Reference LocaleProvider lp,
53 final @Reference TimeZoneProvider timeZoneProvider) {
54 httpClientFactory = hcf;
56 imperial = IMPERIAL_COUNTRIES.contains(lp.getLocale().getCountry());
57 Converter.setTimeZoneProvider(timeZoneProvider);
61 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62 return SUPPORTED_THING_SET.contains(thingTypeUID);
66 protected @Nullable ThingHandler createHandler(Thing thing) {
67 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
68 if (THING_TYPE_CONNECTED_DRIVE_ACCOUNT.equals(thingTypeUID)) {
69 return new ConnectedDriveBridgeHandler((Bridge) thing, httpClientFactory);
70 } else if (SUPPORTED_THING_SET.contains(thingTypeUID)) {
71 VehicleHandler vh = new VehicleHandler(thing, optionProvider, thingTypeUID.getId(), imperial);