use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class HomematicThingHandler method updateDynamicChannelList.
/**
* Update the given thing channel list to reflect the device's current datapoint set
*
* @return true if the list was modified, false if it was not modified
*/
private boolean updateDynamicChannelList(HmDevice device, List<Channel> thingChannels) {
boolean changed = false;
for (HmChannel channel : device.getChannels()) {
if (!channel.isReconfigurable()) {
continue;
}
final String expectedFunction = channel.getDatapoint(HmParamsetType.MASTER, HomematicConstants.DATAPOINT_NAME_CHANNEL_FUNCTION).getOptionValue();
final String propertyName = String.format(PROPERTY_DYNAMIC_FUNCTION_FORMAT, channel.getNumber());
// remove thing channels that were configured for a different function
Iterator<Channel> channelIter = thingChannels.iterator();
while (channelIter.hasNext()) {
Map<String, String> properties = channelIter.next().getProperties();
String function = properties.get(propertyName);
if (function != null && !function.equals(expectedFunction)) {
channelIter.remove();
changed = true;
}
}
for (HmDatapoint dp : channel.getDatapoints()) {
if (HomematicTypeGeneratorImpl.isIgnoredDatapoint(dp) || dp.getParamsetType() != HmParamsetType.VALUES) {
continue;
}
ChannelUID channelUID = UidUtils.generateChannelUID(dp, getThing().getUID());
if (containsChannel(thingChannels, channelUID)) {
// Channel is already present -> channel configuration likely hasn't changed
continue;
}
Map<String, String> channelProps = new HashMap<>();
channelProps.put(propertyName, expectedFunction);
ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
if (channelType == null) {
channelType = HomematicTypeGeneratorImpl.createChannelType(dp, channelTypeUID);
channelTypeProvider.addChannelType(channelType);
}
Channel thingChannel = ChannelBuilder.create(channelUID, MetadataUtils.getItemType(dp)).withProperties(channelProps).withLabel(MetadataUtils.getLabel(dp)).withDescription(MetadataUtils.getDatapointDescription(dp)).withType(channelType.getUID()).build();
thingChannels.add(thingChannel);
changed = true;
}
}
return changed;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class HarmonyHubHandlerFactory method removeChannelTypesForThing.
public void removeChannelTypesForThing(ThingUID uid) {
List<ChannelType> removes = new ArrayList<>();
for (ChannelType c : channelTypes) {
if (c.getUID().getAsString().startsWith(uid.getAsString())) {
removes.add(c);
}
}
channelTypes.removeAll(removes);
}
use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class KM200ChannelTypeProvider method removeChannelTypesForThing.
public void removeChannelTypesForThing(ThingUID uid) {
List<ChannelType> removes = new ArrayList<>();
for (ChannelType c : channelTypes) {
if (c.getUID().getAsString().startsWith(uid.getAsString())) {
removes.add(c);
}
}
channelTypes.removeAll(removes);
}
use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class DsChannelTypeProvider method getChannelTypes.
@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
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;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class HomematicTypeGeneratorImpl method createChannelType.
/**
* Creates the ChannelType for the given datapoint.
*/
public static ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) {
ChannelType channelType;
if (dp.getName().equals(DATAPOINT_NAME_LOWBAT) || dp.getName().equals(DATAPOINT_NAME_LOWBAT_IP)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_LOW_BATTERY;
} else if (dp.getName().equals(VIRTUAL_DATAPOINT_NAME_SIGNAL_STRENGTH)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_SIGNAL_STRENGTH;
} else if (dp.getName().equals(VIRTUAL_DATAPOINT_NAME_BUTTON)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_BUTTON;
} else {
String itemType = MetadataUtils.getItemType(dp);
String category = MetadataUtils.getCategory(dp, itemType);
String label = MetadataUtils.getLabel(dp);
String description = MetadataUtils.getDatapointDescription(dp);
List<StateOption> options = null;
if (dp.isEnumType()) {
options = MetadataUtils.generateOptions(dp, new OptionsBuilder<StateOption>() {
@Override
public StateOption createOption(String value, String description) {
return new StateOption(value, description);
}
});
}
StateDescriptionFragmentBuilder stateFragment = StateDescriptionFragmentBuilder.create();
if (dp.isNumberType()) {
BigDecimal min = MetadataUtils.createBigDecimal(dp.getMinValue());
BigDecimal max = MetadataUtils.createBigDecimal(dp.getMaxValue());
if (ITEM_TYPE_DIMMER.equals(itemType) && (max.compareTo(new BigDecimal("1.0")) == 0 || max.compareTo(new BigDecimal("1.01")) == 0)) {
// For dimmers with a max value of 1.01 or 1.0 the values must be corrected
min = MetadataUtils.createBigDecimal(0);
max = MetadataUtils.createBigDecimal(100);
}
stateFragment.withMinimum(min).withMaximum(max).withPattern(MetadataUtils.getStatePattern(dp)).withReadOnly(dp.isReadOnly());
} else {
stateFragment.withPattern(MetadataUtils.getStatePattern(dp)).withReadOnly(dp.isReadOnly());
}
if (options != null) {
stateFragment.withOptions(options);
}
ChannelTypeBuilder channelTypeBuilder;
EventDescription eventDescription = null;
if (dp.isTrigger()) {
eventDescription = new EventDescription(MetadataUtils.generateOptions(dp, new OptionsBuilder<EventOption>() {
@Override
public EventOption createOption(String value, String description) {
return new EventOption(value, description);
}
}));
channelTypeBuilder = ChannelTypeBuilder.trigger(channelTypeUID, label).withEventDescription(eventDescription);
} else {
channelTypeBuilder = ChannelTypeBuilder.state(channelTypeUID, label, itemType).withStateDescriptionFragment(stateFragment.build());
}
channelType = channelTypeBuilder.isAdvanced(!MetadataUtils.isStandard(dp)).withDescription(description).withCategory(category).withConfigDescriptionURI(configDescriptionUriChannel).build();
}
return channelType;
}
Aggregations