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