forked from openhab/org.openhab.binding.zwave
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ZWaveHandlerFactory.java
72 lines (60 loc) · 2.71 KB
/
ZWaveHandlerFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright (c) 2010-2018 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.zwave.internal;
import static org.openhab.binding.zwave.ZWaveBindingConstants.CONTROLLER_SERIAL;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.io.transport.serial.SerialPortManager;
import org.openhab.binding.zwave.ZWaveBindingConstants;
import org.openhab.binding.zwave.handler.ZWaveSerialHandler;
import org.openhab.binding.zwave.handler.ZWaveThingHandler;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The {@link ZWaveHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Chris Jackson - Initial contribution
*/
@Component(immediate = true, service = { ThingHandlerFactory.class })
public class ZWaveHandlerFactory extends BaseThingHandlerFactory {
private Logger logger = LoggerFactory.getLogger(BaseThingHandlerFactory.class);
private @NonNullByDefault({}) SerialPortManager serialPortManager;
@Reference
protected void setSerialPortManager(final SerialPortManager serialPortManager) {
this.serialPortManager = serialPortManager;
}
protected void unsetSerialPortManager(final SerialPortManager serialPortManager) {
this.serialPortManager = null;
}
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
if (thingTypeUID.equals(ZWaveBindingConstants.ZWAVE_THING_UID)) {
return true;
}
return ZWaveBindingConstants.BINDING_ID.equals(thingTypeUID.getBindingId());
}
@Override
protected ThingHandler createHandler(Thing thing) {
logger.debug("Creating thing {}", thing.getUID());
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
// Handle controllers here
if (thingTypeUID.equals(CONTROLLER_SERIAL)) {
return new ZWaveSerialHandler((Bridge) thing, serialPortManager);
}
// Everything else gets handled in a single handler
return new ZWaveThingHandler(thing);
}
}