]> git.basschouten.com Git - openhab-addons.git/blob
15f5f9cc4a698828bb666ecbdcb4a0bebc6d89a2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.nikohomecontrol.internal;
14
15 import static org.openhab.binding.nikohomecontrol.internal.NikoHomeControlBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlAccessHandler;
20 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlActionHandler;
21 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlBridgeHandler1;
22 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlBridgeHandler2;
23 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlMeterHandler;
24 import org.openhab.binding.nikohomecontrol.internal.handler.NikoHomeControlThermostatHandler;
25 import org.openhab.core.i18n.TimeZoneProvider;
26 import org.openhab.core.net.NetworkAddressService;
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;
36
37 /**
38  * The {@link NikoHomeControlHandlerFactory} is responsible for creating things and thing
39  * handlers.
40  *
41  * @author Mark Herwege - Initial Contribution
42  */
43
44 @NonNullByDefault
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.nikohomecontrol")
46 public class NikoHomeControlHandlerFactory extends BaseThingHandlerFactory {
47
48     private final NetworkAddressService networkAddressService;
49     private final TimeZoneProvider timeZoneProvider;
50
51     @Activate
52     public NikoHomeControlHandlerFactory(final @Reference NetworkAddressService networkAddressService,
53             final @Reference TimeZoneProvider timeZoneProvider) {
54         super();
55         this.networkAddressService = networkAddressService;
56         this.timeZoneProvider = timeZoneProvider;
57     }
58
59     @Override
60     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID) || BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID);
62     }
63
64     @Override
65     protected @Nullable ThingHandler createHandler(Thing thing) {
66         if (BRIDGE_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
67             if (BRIDGEII_THING_TYPE.equals(thing.getThingTypeUID())) {
68                 return new NikoHomeControlBridgeHandler2((Bridge) thing, networkAddressService, timeZoneProvider);
69             } else {
70                 return new NikoHomeControlBridgeHandler1((Bridge) thing, timeZoneProvider);
71             }
72         } else if (ACTION_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
73             return new NikoHomeControlActionHandler(thing);
74         } else if (THERMOSTAT_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
75             return new NikoHomeControlThermostatHandler(thing);
76         } else if (METER_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
77             return new NikoHomeControlMeterHandler(thing);
78         } else if (ACCESS_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
79             return new NikoHomeControlAccessHandler(thing);
80         }
81
82         return null;
83     }
84 }