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