Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Fixed ChannelTypeProvider annotations for 'getChannelTypes' method (#…
Browse files Browse the repository at this point in the history
…6288)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored and kaikreuzer committed Oct 28, 2019
1 parent 8aeeb49 commit 577b6d4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Set;

import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder;
Expand Down Expand Up @@ -185,7 +184,7 @@ public static MeteringTypeEnum getMeteringType(String channelID) {
return null;
}

private static List<String> supportedOutputChannelTypes = new ArrayList<>();
private static final List<String> SUPPORTED_OUTPUT_CHANNEL_TYPES = new ArrayList<>();

/**
* Returns true, if the given channel type id is a output channel.
Expand All @@ -194,7 +193,7 @@ public static MeteringTypeEnum getMeteringType(String channelID) {
* @return true, if channel type id is output channel
*/
public static boolean isOutputChannel(String channelTypeID) {
return supportedOutputChannelTypes.contains(channelTypeID);
return SUPPORTED_OUTPUT_CHANNEL_TYPES.contains(channelTypeID);
}

@Activate
Expand Down Expand Up @@ -229,19 +228,19 @@ protected void init() {
}
if (i == 2) {
channelIDpre = HEATING;
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, TEMPERATURE_CONTROLLED));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, TEMPERATURE_CONTROLLED));
}
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, SWITCH));
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, DIMMER));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, SWITCH));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, DIMMER));
if (i < 2) {
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, "2", STAGE));
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, "3", STAGE));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, "2", STAGE));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, "3", STAGE));
}
}
channelIDpre = SHADE;
supportedOutputChannelTypes.add(channelIDpre);
supportedOutputChannelTypes.add(buildIdentifier(channelIDpre, ANGLE));
supportedOutputChannelTypes.add(SCENE);
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(channelIDpre);
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(buildIdentifier(channelIDpre, ANGLE));
SUPPORTED_OUTPUT_CHANNEL_TYPES.add(SCENE);
}

private String getSensorCategory(SensorEnum sensorType) {
Expand Down Expand Up @@ -455,28 +454,25 @@ private static boolean stringContains(String string, String compare) {

@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
List<ChannelType> channelTypeList = new LinkedList<ChannelType>();
for (String channelTypeId : supportedOutputChannelTypes) {
List<ChannelType> channelTypeList = new LinkedList<>();
for (String channelTypeId : SUPPORTED_OUTPUT_CHANNEL_TYPES) {
channelTypeList.add(
getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, channelTypeId), locale));
}
for (SensorEnum sensorType : SensorEnum.values()) {
channelTypeList.add(getChannelType(
new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, buildIdentifier(sensorType)), locale));
}

for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID,
buildIdentifier(meteringType, MeteringUnitsEnum.WH)), locale));
channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID,
buildIdentifier(TOTAL_PRE, meteringType, MeteringUnitsEnum.WH)), locale));
}

for (DeviceBinarayInputEnum binaryInput : DeviceBinarayInputEnum.values()) {
channelTypeList.add(getChannelType(new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID,
buildIdentifier(BINARY_INPUT_PRE, binaryInput)), locale));
}

return channelTypeList;
}

Expand All @@ -491,7 +487,7 @@ public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale)
.withTags(getSimpleTags(channelID, locale))
.withStateDescription(getSensorStateDescription(sensorType)).build();
} catch (IllegalArgumentException e) {
if (supportedOutputChannelTypes.contains(channelID)) {
if (SUPPORTED_OUTPUT_CHANNEL_TYPES.contains(channelID)) {
return ChannelTypeBuilder
.state(channelTypeUID, getLabelText(channelID, locale), getItemType(channelID))
.withDescription(getDescText(channelID, locale)).withCategory(getCategory(channelID))
Expand Down Expand Up @@ -524,20 +520,7 @@ public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale)
// ignore
}
}

}

return null;

}

@Override
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
return null;
}

@Override
public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
Expand All @@ -56,8 +57,10 @@
* @author Wouter Born - Add null annotations
*/
@NonNullByDefault
@Component(service = { ThingHandlerFactory.class, ChannelTypeProvider.class }, configurationPid = "binding.harmonyhub")
public class HarmonyHubHandlerFactory extends BaseThingHandlerFactory implements ChannelTypeProvider {
@Component(service = { ThingHandlerFactory.class, ChannelTypeProvider.class,
ChannelGroupTypeProvider.class }, configurationPid = "binding.harmonyhub")
public class HarmonyHubHandlerFactory extends BaseThingHandlerFactory
implements ChannelTypeProvider, ChannelGroupTypeProvider {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Stream
.concat(HarmonyHubHandler.SUPPORTED_THING_TYPES_UIDS.stream(),
Expand Down Expand Up @@ -114,7 +117,7 @@ private synchronized void registerHarmonyDeviceDiscoveryService(HarmonyHubHandle
}

@Override
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return channelTypes;
}

Expand All @@ -140,7 +143,7 @@ private synchronized void registerHarmonyDeviceDiscoveryService(HarmonyHubHandle
}

@Override
public @Nullable Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return channelGroupTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public MqttChannelTypeProvider(@Reference ThingTypeRegistry typeRegistry) {
}

@Override
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return types.values();
}

Expand All @@ -80,7 +80,7 @@ public MqttChannelTypeProvider(@Reference ThingTypeRegistry typeRegistry) {
}

@Override
public @Nullable Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
public Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return groups.values();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NUTChannelTypeProvider implements ChannelTypeProvider, ThingHandler
private @Nullable ThingHandler handler;

@Override
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable final Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable final Locale locale) {
return Collections.unmodifiableCollection(map.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.library.CoreItemFactory;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
Expand All @@ -51,10 +49,10 @@ public class SmartMeterChannelTypeProvider implements ChannelTypeProvider, Meter

private final Logger logger = LoggerFactory.getLogger(SmartMeterChannelTypeProvider.class);

private Map<String, ChannelType> obisChannelMap = new ConcurrentHashMap<>();
private final Map<String, ChannelType> obisChannelMap = new ConcurrentHashMap<>();

@Override
public @NonNull Collection<@NonNull ChannelType> getChannelTypes(@Nullable Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return obisChannelMap.values();
}

Expand All @@ -64,17 +62,6 @@ public class SmartMeterChannelTypeProvider implements ChannelTypeProvider, Meter
.findFirst().orElse(null);
}

@Override
public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
@Nullable Locale locale) {
return null;
}

@Override
public @Nullable Collection<@NonNull ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return null;
}

@Override
public void errorOccurred(Throwable e) {
// Nothing to do if there is an reading error...
Expand Down Expand Up @@ -118,7 +105,7 @@ private ChannelType getChannelType(Unit<?> unit, String obis) {

/**
* Gets the {@link ChannelTypeUID} for the given OBIS code.
*
*
* @param obis The obis code.
* @return The {@link ChannelTypeUID} or null.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
Expand All @@ -49,7 +47,7 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
private @NonNullByDefault({}) YamahaZoneThingHandler handler;

@Override
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return Collections.singleton(channelType);
}

Expand All @@ -62,17 +60,6 @@ public class ChannelsTypeProviderAvailableInputs implements ChannelTypeProvider,
}
}

@Override
public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
@Nullable Locale locale) {
return null;
}

@Override
public @Nullable Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return null;
}

public ChannelTypeUID getChannelTypeUID() {
return channelTypeUID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.thing.type.ChannelGroupType;
import org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeProvider;
Expand All @@ -49,7 +47,7 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
private @NonNullByDefault({}) YamahaZoneThingHandler handler;

@Override
public @Nullable Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
public Collection<ChannelType> getChannelTypes(@Nullable Locale locale) {
return Collections.singleton(channelType);
}

Expand All @@ -62,17 +60,6 @@ public class ChannelsTypeProviderPreset implements ChannelTypeProvider, ThingHan
}
}

@Override
public @Nullable ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID,
@Nullable Locale locale) {
return null;
}

@Override
public @Nullable Collection<ChannelGroupType> getChannelGroupTypes(@Nullable Locale locale) {
return null;
}

public ChannelTypeUID getChannelTypeUID() {
return channelTypeUID;
}
Expand Down

0 comments on commit 577b6d4

Please sign in to comment.