2 * Copyright (c) 2010-2021 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.teleinfo.internal.handler;
15 import static org.openhab.binding.teleinfo.internal.TeleinfoBindingConstants.*;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.teleinfo.internal.serial.TeleinfoSerialControllerHandler;
24 import org.openhab.core.io.transport.serial.SerialPortManager;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
36 * The {@link TeleinfoThingHandlerFactory} is responsible for creating things and thing
39 * @author Nicolas SIBERIL - Initial contribution
42 @Component(configurationPid = "binding.teleinfo", service = ThingHandlerFactory.class)
43 public class TeleinfoThingHandlerFactory extends BaseThingHandlerFactory {
45 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream.of(THING_TYPE_SERIAL_CONTROLLER,
46 THING_HC_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_ELECTRICITY_METER_TYPE_UID,
47 THING_TEMPO_CBEMM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_ELECTRICITY_METER_TYPE_UID,
48 THING_HC_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
49 THING_TEMPO_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBEMM_EVO_ICC_ELECTRICITY_METER_TYPE_UID,
50 THING_HC_CBETM_ELECTRICITY_METER_TYPE_UID, THING_BASE_CBETM_ELECTRICITY_METER_TYPE_UID,
51 THING_TEMPO_CBETM_ELECTRICITY_METER_TYPE_UID, THING_EJP_CBETM_ELECTRICITY_METER_TYPE_UID)
52 .collect(Collectors.toSet());
54 private final SerialPortManager serialPortManager;
57 public TeleinfoThingHandlerFactory(@Reference SerialPortManager serialPortManager) {
58 this.serialPortManager = serialPortManager;
62 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
63 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
67 protected @Nullable ThingHandler createHandler(Thing thing) {
68 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
70 if (THING_TYPE_SERIAL_CONTROLLER.equals(thingTypeUID)) {
71 return new TeleinfoSerialControllerHandler((Bridge) thing, serialPortManager);
74 if (SUPPORTED_THING_TYPES_UIDS.contains(thing.getThingTypeUID())) {
75 return new TeleinfoElectricityMeterHandler(thing);
77 throw new IllegalStateException("Teleinfo frame type not supported: " + thing.getThingTypeUID());