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.powermax.internal;
15 import static org.openhab.binding.powermax.internal.PowermaxBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.powermax.internal.handler.PowermaxBridgeHandler;
20 import org.openhab.binding.powermax.internal.handler.PowermaxThingHandler;
21 import org.openhab.core.config.core.Configuration;
22 import org.openhab.core.i18n.TimeZoneProvider;
23 import org.openhab.core.io.transport.serial.SerialPortManager;
24 import org.openhab.core.thing.Bridge;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.ThingUID;
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.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
36 * The {@link PowermaxHandlerFactory} is responsible for creating things and thing
39 * @author Laurent Garnier - Initial contribution
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.powermax")
43 public class PowermaxHandlerFactory extends BaseThingHandlerFactory {
45 private final SerialPortManager serialPortManager;
46 private final TimeZoneProvider timeZoneProvider;
49 public PowermaxHandlerFactory(final @Reference SerialPortManager serialPortManager,
50 final @Reference TimeZoneProvider timeZoneProvider) {
51 this.serialPortManager = serialPortManager;
52 this.timeZoneProvider = timeZoneProvider;
56 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID) || SUPPORTED_BRIDGE_TYPES_UIDS.contains(thingTypeUID);
61 public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
62 @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
63 if (SUPPORTED_BRIDGE_TYPES_UIDS.contains(thingTypeUID)) {
64 return super.createThing(thingTypeUID, configuration, thingUID, null);
65 } else if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
67 if (bridgeUID != null && thingUID != null) {
68 newThingUID = new ThingUID(thingTypeUID, bridgeUID, thingUID.getId());
70 newThingUID = thingUID;
72 return super.createThing(thingTypeUID, configuration, newThingUID, bridgeUID);
74 throw new IllegalArgumentException(
75 "The thing type " + thingTypeUID + " is not supported by the Powermax binding.");
79 protected @Nullable ThingHandler createHandler(Thing thing) {
80 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
82 if (SUPPORTED_BRIDGE_TYPES_UIDS.contains(thingTypeUID)) {
83 return new PowermaxBridgeHandler((Bridge) thing, serialPortManager, timeZoneProvider);
84 } else if (SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) {
85 return new PowermaxThingHandler(thing);