]> git.basschouten.com Git - openhab-addons.git/blob
96674ce5c2d44392ba0e9030fce9d108b8f3c0e2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.pixometer.internal;
14
15 import java.util.Set;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
18
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;
30
31 /**
32  * The {@link PixometerHandlerFactory} is responsible for creating things and thing
33  * handlers.
34  *
35  * @author Jerome Luckenbach - Initial contribution
36  */
37 @NonNullByDefault
38 @Component(configurationPid = "binding.pixometer", service = ThingHandlerFactory.class)
39 public class PixometerHandlerFactory extends BaseThingHandlerFactory {
40
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());
44
45     @Override
46     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
47         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
48     }
49
50     @Override
51     protected @Nullable ThingHandler createHandler(Thing thing) {
52         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
53
54         if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_ENERGYMETER)) {
55             return new MeterHandler(thing);
56         }
57
58         if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_GASMETER)) {
59             return new MeterHandler(thing);
60         }
61
62         if (thingTypeUID.equals(PixometerBindingConstants.THING_TYPE_WATERMETER)) {
63             return new MeterHandler(thing);
64         }
65
66         if (thingTypeUID.equals(PixometerBindingConstants.BRIDGE_THING_TYPE)) {
67             return new AccountHandler((Bridge) thing);
68         }
69
70         return null;
71     }
72 }