use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class HomematicTypeGeneratorImpl method generate.
@Override
public void generate(HmDevice device) {
if (thingTypeProvider != null) {
ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
ThingType tt = thingTypeProvider.getInternalThingType(thingTypeUID);
if (tt == null || device.isGatewayExtras()) {
logger.debug("Generating ThingType for device '{}' with {} datapoints", device.getType(), device.getDatapointCount());
List<ChannelGroupType> groupTypes = new ArrayList<>();
for (HmChannel channel : device.getChannels()) {
List<ChannelDefinition> channelDefinitions = new ArrayList<>();
// those will be populated dynamically during thing initialization
if (!channel.isReconfigurable()) {
// generate channel
for (HmDatapoint dp : channel.getDatapoints()) {
if (!isIgnoredDatapoint(dp) && dp.getParamsetType() == HmParamsetType.VALUES) {
ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
if (channelType == null) {
channelType = createChannelType(dp, channelTypeUID);
channelTypeProvider.addChannelType(channelType);
}
ChannelDefinition channelDef = new ChannelDefinitionBuilder(dp.getName(), channelType.getUID()).build();
channelDefinitions.add(channelDef);
}
}
}
// generate group
ChannelGroupTypeUID groupTypeUID = UidUtils.generateChannelGroupTypeUID(channel);
ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
if (groupType == null || device.isGatewayExtras()) {
String groupLabel = String.format("%s", channel.getType() == null ? null : MiscUtils.capitalize(channel.getType().replace("_", " ")));
groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel).withChannelDefinitions(channelDefinitions).build();
channelGroupTypeProvider.addChannelGroupType(groupType);
groupTypes.add(groupType);
}
}
tt = createThingType(device, groupTypes);
thingTypeProvider.addThingType(tt);
}
addFirmware(device);
}
}
use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.
the class AbstractMieleThingHandlerTest method createChannelsForThingHandler.
private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
ChannelTypeRegistry channelTypeRegistry = getService(ChannelTypeRegistry.class, ChannelTypeRegistry.class);
assertNotNull(channelTypeRegistry);
ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class, ThingTypeRegistry.class);
assertNotNull(thingTypeRegistry);
ThingType thingType = thingTypeRegistry.getThingType(thingTypeUid);
assertNotNull(thingType);
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
assertNotNull(channelDefinitions);
List<Channel> channels = new ArrayList<Channel>();
for (ChannelDefinition channelDefinition : channelDefinitions) {
ChannelTypeUID channelTypeUid = channelDefinition.getChannelTypeUID();
assertNotNull(channelTypeUid);
ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUid);
assertNotNull(channelType);
String acceptedItemType = channelType.getItemType();
assertNotNull(acceptedItemType);
String channelId = channelDefinition.getId();
assertNotNull(channelId);
ChannelUID channelUid = new ChannelUID(thingUid, channelId);
assertNotNull(channelUid);
Channel channel = ChannelBuilder.create(channelUid, acceptedItemType).build();
assertNotNull(channel);
channels.add(channel);
}
return channels;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class AutoUpdateManager method shouldAutoUpdate.
private Recommendation shouldAutoUpdate(Item item) {
String itemName = item.getName();
Recommendation ret = Recommendation.REQUIRED;
// check if the item is a group item
if (item instanceof GroupItem) {
return Recommendation.DONT;
}
List<ChannelUID> linkedChannelUIDs = new ArrayList<>();
for (ItemChannelLink link : itemChannelLinkRegistry.getLinks(itemName)) {
linkedChannelUIDs.add(link.getLinkedUID());
}
// check if there is any channel ONLINE
List<ChannelUID> onlineChannelUIDs = new ArrayList<>();
for (ChannelUID channelUID : linkedChannelUIDs) {
Thing thing = thingRegistry.get(channelUID.getThingUID());
if (//
thing == null || //
thing.getChannel(channelUID.getId()) == null || //
thing.getHandler() == null || //
!ThingStatus.ONLINE.equals(thing.getStatus())) {
continue;
}
onlineChannelUIDs.add(channelUID);
}
if (!linkedChannelUIDs.isEmpty() && onlineChannelUIDs.isEmpty()) {
// none of the linked channels is able to process the command
return Recommendation.REVERT;
}
for (ChannelUID channelUID : onlineChannelUIDs) {
Thing thing = thingRegistry.get(channelUID.getThingUID());
if (thing == null) {
continue;
}
AutoUpdatePolicy policy = AutoUpdatePolicy.DEFAULT;
Channel channel = thing.getChannel(channelUID.getId());
if (channel != null) {
AutoUpdatePolicy channelpolicy = channel.getAutoUpdatePolicy();
if (channelpolicy != null) {
policy = channelpolicy;
} else {
ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
if (channelType != null && channelType.getAutoUpdatePolicy() != null) {
policy = channelType.getAutoUpdatePolicy();
}
}
}
switch(policy) {
case VETO:
ret = Recommendation.DONT;
break;
case DEFAULT:
if (ret == Recommendation.REQUIRED || ret == Recommendation.RECOMMENDED) {
ret = Recommendation.OPTIMISTIC;
}
break;
case RECOMMEND:
if (ret == Recommendation.REQUIRED) {
ret = Recommendation.RECOMMENDED;
}
break;
}
}
return ret;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class ChannelCommandDescriptionProvider method getCommandDescription.
@Override
@Nullable
public CommandDescription getCommandDescription(String itemName, @Nullable Locale locale) {
Set<ChannelUID> boundChannels = itemChannelLinkRegistry.getBoundChannels(itemName);
if (!boundChannels.isEmpty()) {
ChannelUID channelUID = boundChannels.iterator().next();
Channel channel = thingRegistry.getChannel(channelUID);
if (channel != null) {
CommandDescription commandDescription = null;
ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale);
if (channelType != null) {
commandDescription = channelType.getCommandDescription();
}
CommandDescription dynamicCommandDescription = getDynamicCommandDescription(channel, commandDescription, locale);
if (dynamicCommandDescription != null) {
return dynamicCommandDescription;
}
return commandDescription;
}
}
return null;
}
use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.
the class ThingTypeXmlProvider method addingFinished.
@Override
public synchronized void addingFinished() {
// create channel types
for (ChannelTypeXmlResult type : channelTypeRefs) {
ChannelType channelType = type.toChannelType();
try {
channelTypeProvider.add(bundle, channelType);
} catch (RuntimeException e) {
logger.error("Could not register ChannelType: {}", channelType.getUID(), e);
}
}
// create channel group types
for (ChannelGroupTypeXmlResult type : channelGroupTypeRefs) {
try {
channelGroupTypeProvider.add(bundle, type.toChannelGroupType());
} catch (RuntimeException e) {
logger.error("Could not register ChannelGroupType: {}", type.getUID(), e);
}
}
// create thing and bridge types
for (ThingTypeXmlResult type : thingTypeRefs) {
try {
thingTypeProvider.add(bundle, type.toThingType());
} catch (RuntimeException e) {
logger.error("Could not register ThingType: {}", type.getUID(), e);
}
}
// release temporary cache
thingTypeRefs.clear();
channelGroupTypeRefs.clear();
channelTypeRefs.clear();
}
Aggregations