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.systeminfo.internal;
15 import static org.openhab.binding.systeminfo.internal.SystemInfoBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.systeminfo.internal.handler.SystemInfoHandler;
22 import org.openhab.binding.systeminfo.internal.model.SystemInfoInterface;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.ThingHandlerFactory;
28 import org.osgi.service.component.annotations.Component;
29 import org.osgi.service.component.annotations.Reference;
32 * The {@link SystemInfoHandlerFactory} is responsible for creating things and thing
35 * @author Svilen Valkanov - Initial contribution
36 * @author Lyubomir Papazov - Pass systeminfo service to the SystemInfoHandler constructor
37 * @author Wouter Born - Add null annotations
38 * @author Mark Herwege - Add dynamic creation of extra channels
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.systeminfo")
42 public class SystemInfoHandlerFactory extends BaseThingHandlerFactory {
43 private @NonNullByDefault({}) SystemInfoInterface systeminfo;
44 private @NonNullByDefault({}) SystemInfoThingTypeProvider thingTypeProvider;
46 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_COMPUTER,
47 THING_TYPE_COMPUTER_IMPL);
50 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
55 protected @Nullable ThingHandler createHandler(Thing thing) {
56 if (THING_TYPE_COMPUTER.equals(thing.getThingTypeUID())) {
57 if (thingTypeProvider.getThingType(THING_TYPE_COMPUTER_IMPL, null) == null) {
58 thingTypeProvider.createThingType(THING_TYPE_COMPUTER_IMPL);
59 // Save the current channels configs, will be restored after thing type change.
60 thingTypeProvider.storeChannelsConfig(thing);
62 return new SystemInfoHandler(thing, thingTypeProvider, systeminfo);
63 } else if (THING_TYPE_COMPUTER_IMPL.equals(thing.getThingTypeUID())) {
64 return new SystemInfoHandler(thing, thingTypeProvider, systeminfo);
70 public void bindSystemInfo(SystemInfoInterface systeminfo) {
71 this.systeminfo = systeminfo;
74 public void unbindSystemInfo(SystemInfoInterface systeminfo) {
75 this.systeminfo = null;
79 public void setSystemInfoThingTypeProvider(SystemInfoThingTypeProvider thingTypeProvider) {
80 this.thingTypeProvider = thingTypeProvider;
83 public void unsetSystemInfoThingTypeProvider(SystemInfoThingTypeProvider thingTypeProvider) {
84 this.thingTypeProvider = null;