2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.regoheatpump.internal;
15 import static org.openhab.binding.regoheatpump.internal.RegoHeatPumpBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
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;
39 * The {@link RegoHeatPumpHandlerFactory} is responsible for creating things and thing
42 * @author Boris Krivonog - Initial contribution
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.regoheatpump")
46 public class RegoHeatPumpHandlerFactory extends BaseThingHandlerFactory {
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()));
52 private final SerialPortManager serialPortManager;
55 public RegoHeatPumpHandlerFactory(final @Reference SerialPortManager serialPortManager) {
56 this.serialPortManager = serialPortManager;
60 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
61 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
65 protected @Nullable ThingHandler createHandler(Thing thing) {
66 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
68 if (thingTypeUID.equals(THING_TYPE_IP_REGO6XX)) {
69 return new IpRego6xxHeatPumpHandler(thing);
72 if (thingTypeUID.equals(THING_TYPE_SERIAL_REGO6XX)) {
73 return new SerialRego6xxHeatPumpHandler(thing, serialPortManager);
76 if (thingTypeUID.equals(THING_TYPE_IP_HUSDATA)) {
77 return new IpHusdataHandler(thing);
80 if (thingTypeUID.equals(THING_TYPE_SERIAL_HUSDATA)) {
81 return new SerialHusdataHandler(thing, serialPortManager);