]> git.basschouten.com Git - openhab-addons.git/blob
76742eb1d8195abca2ae95b4c3cea8dfce8210b0
[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.bmwconnecteddrive.internal;
14
15 import static org.openhab.binding.bmwconnecteddrive.internal.ConnectedDriveConstants.*;
16
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;
35
36 /**
37  * The {@link ConnectedDriveHandlerFactory} is responsible for creating things and thing
38  * handlers.
39  *
40  * @author Bernd Weymann - Initial contribution
41  */
42 @NonNullByDefault
43 @Component(configurationPid = "binding.bmwconnecteddrive", service = ThingHandlerFactory.class)
44 public class ConnectedDriveHandlerFactory extends BaseThingHandlerFactory {
45
46     private final HttpClientFactory httpClientFactory;
47     private final BMWConnectedDriveOptionProvider optionProvider;
48     private boolean imperial = false;
49
50     @Activate
51     public ConnectedDriveHandlerFactory(final @Reference HttpClientFactory hcf,
52             final @Reference BMWConnectedDriveOptionProvider op, final @Reference LocaleProvider lp,
53             final @Reference TimeZoneProvider timeZoneProvider) {
54         httpClientFactory = hcf;
55         optionProvider = op;
56         imperial = IMPERIAL_COUNTRIES.contains(lp.getLocale().getCountry());
57         Converter.setTimeZoneProvider(timeZoneProvider);
58     }
59
60     @Override
61     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62         return SUPPORTED_THING_SET.contains(thingTypeUID);
63     }
64
65     @Override
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);
72             return vh;
73         }
74         return null;
75     }
76 }