]> git.basschouten.com Git - openhab-addons.git/blob
cb9004b1d6e29b49f76210ac1f3a92206c071a6f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.regoheatpump.internal;
14
15 import static org.openhab.binding.regoheatpump.internal.RegoHeatPumpBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.regoheatpump.internal.handler.IpHusdataHandler;
25 import org.openhab.binding.regoheatpump.internal.handler.IpRego6xxHeatPumpHandler;
26 import org.openhab.binding.regoheatpump.internal.handler.SerialHusdataHandler;
27 import org.openhab.binding.regoheatpump.internal.handler.SerialRego6xxHeatPumpHandler;
28 import org.openhab.core.io.transport.serial.SerialPortManager;
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 RegoHeatPumpHandlerFactory} is responsible for creating things and thing
40  * handlers.
41  *
42  * @author Boris Krivonog - Initial contribution
43  */
44 @NonNullByDefault
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.regoheatpump")
46 public class RegoHeatPumpHandlerFactory extends BaseThingHandlerFactory {
47
48     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(Stream
49             .of(THING_TYPE_IP_REGO6XX, THING_TYPE_SERIAL_REGO6XX, THING_TYPE_IP_HUSDATA, THING_TYPE_SERIAL_HUSDATA)
50             .collect(Collectors.toSet()));
51
52     private final SerialPortManager serialPortManager;
53
54     @Activate
55     public RegoHeatPumpHandlerFactory(final @Reference SerialPortManager serialPortManager) {
56         this.serialPortManager = serialPortManager;
57     }
58
59     @Override
60     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
62     }
63
64     @Override
65     protected @Nullable ThingHandler createHandler(Thing thing) {
66         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
67
68         if (thingTypeUID.equals(THING_TYPE_IP_REGO6XX)) {
69             return new IpRego6xxHeatPumpHandler(thing);
70         }
71
72         if (thingTypeUID.equals(THING_TYPE_SERIAL_REGO6XX)) {
73             return new SerialRego6xxHeatPumpHandler(thing, serialPortManager);
74         }
75
76         if (thingTypeUID.equals(THING_TYPE_IP_HUSDATA)) {
77             return new IpHusdataHandler(thing);
78         }
79
80         if (thingTypeUID.equals(THING_TYPE_SERIAL_HUSDATA)) {
81             return new SerialHusdataHandler(thing, serialPortManager);
82         }
83
84         return null;
85     }
86 }