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.foobot.internal;
15 import static org.openhab.binding.foobot.internal.FoobotBindingConstants.*;
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.foobot.internal.handler.FoobotAccountHandler;
25 import org.openhab.binding.foobot.internal.handler.FoobotDeviceHandler;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.openhab.core.thing.Bridge;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Activate;
34 import org.osgi.service.component.annotations.Component;
35 import org.osgi.service.component.annotations.Reference;
38 * The {@link FoobotHandlerFactory} is responsible for creating things and thing handlers.
40 * @author Divya Chauhan - Initial contribution
41 * @author George Katsis - Add Bridge thing type
42 * @author Hilbrand Bouwkamp - Completed implementation
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.foobot")
46 public class FoobotHandlerFactory extends BaseThingHandlerFactory {
48 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPE_UIDS = Collections
49 .unmodifiableSet(Stream.of(BRIDGE_TYPE_FOOBOTACCOUNT, THING_TYPE_FOOBOT).collect(Collectors.toSet()));
51 public static final Set<ThingTypeUID> DISCOVERABLE_THING_TYPE_UIDS = Set.of(THING_TYPE_FOOBOT);
53 private final FoobotApiConnector connector = new FoobotApiConnector();
56 public FoobotHandlerFactory(@Reference final HttpClientFactory httpClientFactory) {
57 connector.setHttpClient(httpClientFactory.getCommonHttpClient());
61 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62 return SUPPORTED_THING_TYPE_UIDS.contains(thingTypeUID);
66 protected @Nullable ThingHandler createHandler(Thing thing) {
67 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
69 if (thingTypeUID.equals(THING_TYPE_FOOBOT)) {
70 return new FoobotDeviceHandler(thing, connector);
71 } else if (thingTypeUID.equals(BRIDGE_TYPE_FOOBOTACCOUNT)) {
72 return new FoobotAccountHandler((Bridge) thing, connector);