use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy in project smarthome by eclipse.
the class ChannelTypeConverter method unmarshalType.
@Override
protected ChannelTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
boolean advanced = readBoolean(attributes, "advanced", false);
boolean system = readBoolean(attributes, "system", false);
String uid = system ? XmlHelper.getSystemUID(super.getID(attributes)) : super.getUID(attributes, context);
ChannelTypeUID channelTypeUID = new ChannelTypeUID(uid);
String itemType = readItemType(nodeIterator);
String kind = readKind(nodeIterator);
String label = super.readLabel(nodeIterator);
String description = super.readDescription(nodeIterator);
String category = readCategory(nodeIterator);
Set<String> tags = readTags(nodeIterator);
StateDescription stateDescription = readStateDescription(nodeIterator);
CommandDescription commandDescription = readCommandDescription(nodeIterator);
EventDescription eventDescription = readEventDescription(nodeIterator);
AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);
Object[] configDescriptionObjects = super.getConfigDescriptionObjects(nodeIterator);
if (kind == null) {
// Default for kind is 'state'
kind = "state";
}
ChannelKind cKind = ChannelKind.parse(kind);
URI configDescriptionURI = (URI) configDescriptionObjects[0];
ChannelType channelType = null;
if (cKind == ChannelKind.STATE) {
StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withStateDescription(stateDescription).withAutoUpdatePolicy(autoUpdatePolicy).withCommandDescription(commandDescription);
channelType = builder.build();
} else if (cKind == ChannelKind.TRIGGER) {
channelType = ChannelTypeBuilder.trigger(channelTypeUID, label).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withEventDescription(eventDescription).build();
}
ChannelTypeXmlResult channelTypeXmlResult = new ChannelTypeXmlResult(channelType, (ConfigDescription) configDescriptionObjects[1], system);
return channelTypeXmlResult;
}
use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy in project smarthome by eclipse.
the class ChannelConverter method unmarshalType.
protected ChannelXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
String id = attributes.get("id");
String typeId = attributes.get("typeId");
String label = (String) nodeIterator.nextValue("label", false);
String description = (String) nodeIterator.nextValue("description", false);
List<NodeValue> properties = getProperties(nodeIterator);
AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);
ChannelXmlResult channelXmlResult = new ChannelXmlResult(id, typeId, label, description, properties, autoUpdatePolicy);
return channelXmlResult;
}
use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy in project smarthome by eclipse.
the class AutoUpdateManager method shouldAutoUpdate.
private Recommendation shouldAutoUpdate(String itemName) {
Recommendation ret = Recommendation.REQUIRED;
List<ChannelUID> linkedChannelUIDs = new ArrayList<>();
for (ItemChannelLink link : itemChannelLinkRegistry.getAll()) {
if (link.getItemName().equals(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;
}
Aggregations