2 * Copyright (c) 2010-2024 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.salus.internal;
15 import static org.openhab.binding.salus.internal.SalusBindingConstants.SALUS_DEVICE_TYPE;
16 import static org.openhab.binding.salus.internal.SalusBindingConstants.SALUS_IT600_DEVICE_TYPE;
17 import static org.openhab.binding.salus.internal.SalusBindingConstants.SALUS_SERVER_TYPE;
18 import static org.openhab.binding.salus.internal.SalusBindingConstants.SUPPORTED_THING_TYPES_UIDS;
20 import java.util.Hashtable;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.salus.internal.discovery.CloudDiscovery;
25 import org.openhab.binding.salus.internal.handler.CloudBridgeHandler;
26 import org.openhab.binding.salus.internal.handler.DeviceHandler;
27 import org.openhab.binding.salus.internal.handler.It600Handler;
28 import org.openhab.core.config.discovery.DiscoveryService;
29 import org.openhab.core.io.net.http.HttpClientFactory;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
34 import org.openhab.core.thing.binding.ThingHandler;
35 import org.openhab.core.thing.binding.ThingHandlerFactory;
36 import org.osgi.service.component.annotations.Activate;
37 import org.osgi.service.component.annotations.Component;
38 import org.osgi.service.component.annotations.Reference;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * The {@link SalusHandlerFactory} is responsible for creating things and thing
46 * @author Martin Grzeslowski - Initial contribution
49 @Component(configurationPid = "binding.salus", service = ThingHandlerFactory.class)
50 public class SalusHandlerFactory extends BaseThingHandlerFactory {
52 private final Logger logger = LoggerFactory.getLogger(SalusHandlerFactory.class);
53 protected final @NonNullByDefault({}) HttpClientFactory httpClientFactory;
56 public SalusHandlerFactory(@Reference HttpClientFactory httpClientFactory) {
57 this.httpClientFactory = httpClientFactory;
61 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
62 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
66 protected @Nullable ThingHandler createHandler(Thing thing) {
67 var thingTypeUID = thing.getThingTypeUID();
69 if (SALUS_DEVICE_TYPE.equals(thingTypeUID)) {
70 return newSalusDevice(thing);
72 if (SALUS_IT600_DEVICE_TYPE.equals(thingTypeUID)) {
73 return newIt600(thing);
75 if (SALUS_SERVER_TYPE.equals(thingTypeUID)) {
76 return newSalusCloudBridge(thing);
82 private ThingHandler newSalusDevice(Thing thing) {
83 logger.debug("New Salus Device {}", thing.getUID().getId());
84 return new DeviceHandler(thing);
87 private ThingHandler newIt600(Thing thing) {
88 logger.debug("Registering IT600");
89 return new It600Handler(thing);
92 private ThingHandler newSalusCloudBridge(Thing thing) {
93 var handler = new CloudBridgeHandler((Bridge) thing, httpClientFactory);
94 var cloudDiscovery = new CloudDiscovery(handler, handler, handler.getThing().getUID());
95 registerThingDiscovery(cloudDiscovery);
99 private synchronized void registerThingDiscovery(DiscoveryService discoveryService) {
100 bundleContext.registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>());