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.pixometer.internal;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.pixometer.handler.AccountHandler;
22 import org.openhab.binding.pixometer.handler.MeterHandler;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Component;
32 * The {@link PixometerHandlerFactory} is responsible for creating things and thing
35 * @author Jerome Luckenbach - Initial contribution
38 @Component(configurationPid = "binding.pixometer", service = ThingHandlerFactory.class)
39 public class PixometerHandlerFactory extends BaseThingHandlerFactory {
41 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
42 .of(PixometerBindingConstants.BRIDGE_THING_TYPES_UIDS, PixometerBindingConstants.SUPPORTED_THING_TYPES_UIDS)
43 .flatMap(Set::stream).collect(Collectors.toSet());
46 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
47 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
51 protected @Nullable ThingHandler createHandler(Thing thing) {
52 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
54 if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_ENERGYMETER)) {
55 return new MeterHandler(thing);
58 if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_GASMETER)) {
59 return new MeterHandler(thing);
62 if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_WATERMETER)) {
63 return new MeterHandler(thing);
66 if (thingTypeUID.equals(PixometerBindingConstants.BRIDGE_THING_TYPE)) {
67 return new AccountHandler((Bridge) thing);