mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
[DSL] Removed deleted things from internal map (#1058)
* Applied formatter * Fixed warnings * Removed deleted things from internal map Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
8b72770bf3
commit
e8fcba2ccf
@ -56,7 +56,6 @@ import org.eclipse.smarthome.model.thing.thing.ModelPropertyContainer
|
||||
import org.eclipse.smarthome.model.thing.thing.ModelThing
|
||||
import org.eclipse.smarthome.model.thing.thing.ThingModel
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
import org.osgi.framework.FrameworkUtil
|
||||
import org.osgi.service.component.annotations.Component
|
||||
import org.osgi.service.component.annotations.Reference
|
||||
import org.slf4j.Logger
|
||||
@ -74,9 +73,8 @@ import org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy
|
||||
* factory cannot load a thing yet (bug 470368),
|
||||
* added delay until ThingTypes are fully loaded
|
||||
* @author Markus Rathgeb - Add locale provider support
|
||||
*
|
||||
*/
|
||||
@Component(immediate=true, service=ThingProvider)
|
||||
@Component(immediate=true, service=ThingProvider)
|
||||
class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvider, ModelRepositoryChangeListener, ReadyService.ReadyTracker {
|
||||
|
||||
private static final String XML_THING_TYPE = "esh.xmlThingTypes";
|
||||
@ -123,22 +121,22 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
if (model === null) {
|
||||
return
|
||||
}
|
||||
flattenModelThings(model.things).map[
|
||||
flattenModelThings(model.things).map [
|
||||
// Get the ThingHandlerFactories
|
||||
val ThingUID thingUID = constructThingUID
|
||||
if (thingUID !== null) {
|
||||
val thingTypeUID = constructThingTypeUID(thingUID)
|
||||
return thingHandlerFactories.findFirst[
|
||||
return thingHandlerFactories.findFirst [
|
||||
supportsThingType(thingTypeUID)
|
||||
]
|
||||
} else {
|
||||
// ignore the Thing because its definition is broken
|
||||
return null
|
||||
}
|
||||
]?.filter[
|
||||
]?.filter [
|
||||
// Drop it if there is no ThingHandlerFactory yet which can handle it
|
||||
it !== null
|
||||
]?.toSet?.forEach[
|
||||
]?.toSet?.forEach [
|
||||
// Execute for each unique ThingHandlerFactory
|
||||
createThingsFromModelForThingHandlerFactory(modelName, it)
|
||||
]
|
||||
@ -153,7 +151,9 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
val bindingId = new ThingUID(modelThing.bridgeUID).bindingId
|
||||
return new ThingUID(bindingId, modelThing.thingTypeId, modelThing.thingId)
|
||||
} else {
|
||||
logger.warn("Thing {} does not have a bridge so it needs to be defined in full notation like <bindingId>:{}:{}", modelThing.thingTypeId, modelThing.thingTypeId, modelThing.thingId)
|
||||
logger.warn(
|
||||
"Thing {} does not have a bridge so it needs to be defined in full notation like <bindingId>:{}:{}",
|
||||
modelThing.thingTypeId, modelThing.thingTypeId, modelThing.thingId)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -186,10 +186,11 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
])
|
||||
])
|
||||
|
||||
return things + flattenModelThings(things.filter(typeof(ModelBridge)).map(b | b.things).flatten);
|
||||
return things + flattenModelThings(things.filter(typeof(ModelBridge)).map(b|b.things).flatten);
|
||||
}
|
||||
|
||||
def private void createThing(ModelThing modelThing, Collection<Thing> thingList, ThingHandlerFactory thingHandlerFactory) {
|
||||
def private void createThing(ModelThing modelThing, Collection<Thing> thingList,
|
||||
ThingHandlerFactory thingHandlerFactory) {
|
||||
val ThingUID thingUID = getThingUID(modelThing, null)
|
||||
if (thingUID === null) {
|
||||
// ignore the Thing because its definition is broken
|
||||
@ -213,11 +214,11 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
|
||||
val thingType = thingTypeUID.thingType
|
||||
|
||||
val label = if (modelThing.label !== null) modelThing.label else thingType?.label
|
||||
val label = if(modelThing.label !== null) modelThing.label else thingType?.label
|
||||
|
||||
val location = modelThing.location
|
||||
|
||||
val ThingUID bridgeUID = if (modelThing.bridgeUID !== null) new ThingUID(modelThing.bridgeUID)
|
||||
val ThingUID bridgeUID = if(modelThing.bridgeUID !== null) new ThingUID(modelThing.bridgeUID)
|
||||
val thingFromHandler = getThingFromThingHandlerFactories(thingTypeUID, label, configuration, thingUID,
|
||||
bridgeUID, thingHandlerFactory)
|
||||
|
||||
@ -368,16 +369,13 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
} else {
|
||||
itemType = it.type
|
||||
|
||||
val kind = if (it.channelKind === null) "State" else it.channelKind
|
||||
val kind = if(it.channelKind === null) "State" else it.channelKind
|
||||
parsedKind = ChannelKind.parse(kind)
|
||||
}
|
||||
|
||||
var channel = ChannelBuilder.create(new ChannelUID(thingUID, id), itemType)
|
||||
.withKind(parsedKind)
|
||||
.withConfiguration(configuration)
|
||||
.withType(channelTypeUID)
|
||||
.withLabel(label)
|
||||
.withAutoUpdatePolicy(autoUpdatePolicy)
|
||||
var channel = ChannelBuilder.create(new ChannelUID(thingUID, id), itemType).withKind(parsedKind).
|
||||
withConfiguration(configuration).withType(channelTypeUID).withLabel(label).
|
||||
withAutoUpdatePolicy(autoUpdatePolicy)
|
||||
channels += channel.build()
|
||||
}
|
||||
]
|
||||
@ -386,8 +384,8 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
val channelType = it.channelTypeUID.channelType
|
||||
if (channelType !== null) {
|
||||
channels +=
|
||||
ChannelBuilder.create(new ChannelUID(thingTypeUID, thingUID, id), channelType.itemType).
|
||||
withType(it.channelTypeUID).withAutoUpdatePolicy(channelType.autoUpdatePolicy).build
|
||||
ChannelBuilder.create(new ChannelUID(thingUID, id), channelType.itemType).withType(
|
||||
it.channelTypeUID).withAutoUpdatePolicy(channelType.autoUpdatePolicy).build
|
||||
} else {
|
||||
logger.warn(
|
||||
"Could not create channel '{}' for thing '{}', because channel type '{}' could not be found.",
|
||||
@ -403,9 +401,9 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
if (channelType.configDescriptionURI !== null) {
|
||||
val configDescription = configDescriptionRegistry.getConfigDescription(channelType.configDescriptionURI)
|
||||
if (configDescription !== null) {
|
||||
configDescription.parameters.filter[
|
||||
configDescription.parameters.filter [
|
||||
^default !== null && configuration.get(name) === null
|
||||
].forEach[
|
||||
].forEach [
|
||||
val value = getDefaultValueAsCorrectType(type, ^default)
|
||||
if (value !== null) {
|
||||
configuration.put(name, value);
|
||||
@ -431,12 +429,12 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
return null
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.warn("Could not parse default value '{}' as type '{}': {}", defaultValue, parameterType, ex.getMessage(), ex);
|
||||
logger.warn("Could not parse default value '{}' as type '{}': {}", defaultValue, parameterType,
|
||||
ex.getMessage(), ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def private createConfiguration(ModelPropertyContainer propertyContainer) {
|
||||
val configuration = new Configuration
|
||||
propertyContainer.properties.forEach [
|
||||
@ -490,12 +488,15 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
val newThingUIDs = model.allThingUIDs
|
||||
val removedThings = oldThings.filter[!newThingUIDs.contains(it.UID)]
|
||||
removedThings.forEach [
|
||||
logger.debug("Removing thing '{}' from model '{}'.", it.UID, modelName)
|
||||
notifyListenersAboutRemovedElement
|
||||
]
|
||||
createThingsFromModel(modelName)
|
||||
thingsMap.get(modelName).removeAll(removedThings)
|
||||
}
|
||||
}
|
||||
case org.eclipse.smarthome.model.core.EventType.REMOVED: {
|
||||
logger.debug("Removing all things from model '{}'.", modelName)
|
||||
val things = thingsMap.remove(modelName) ?: newArrayList
|
||||
things.forEach [
|
||||
notifyListenersAboutRemovedElement
|
||||
@ -511,7 +512,7 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
|
||||
def private Set<ThingUID> getAllThingUIDs(List<ModelThing> thingList, ThingUID parentUID) {
|
||||
val ret = new HashSet<ThingUID>()
|
||||
thingList.forEach[
|
||||
thingList.forEach [
|
||||
val thingUID = getThingUID(it, parentUID)
|
||||
ret.add(thingUID)
|
||||
if (it instanceof ModelBridge) {
|
||||
@ -575,7 +576,7 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
|
||||
def thingHandlerFactoryAdded(ThingHandlerFactory thingHandlerFactory) {
|
||||
thingsMap.keySet.forEach [
|
||||
//create things for this specific thingHandlerFactory from the model.
|
||||
// create things for this specific thingHandlerFactory from the model.
|
||||
createThingsFromModelForThingHandlerFactory(it, thingHandlerFactory)
|
||||
]
|
||||
}
|
||||
@ -600,9 +601,9 @@ class GenericThingProvider extends AbstractProvider<Thing> implements ThingProvi
|
||||
}
|
||||
|
||||
def private handleXmlThingTypesLoaded(String bsn) {
|
||||
thingHandlerFactories.filter[
|
||||
thingHandlerFactories.filter [
|
||||
getBundleName.equals(bsn)
|
||||
].forEach[ thingHandlerFactory |
|
||||
].forEach [ thingHandlerFactory |
|
||||
thingHandlerFactory.thingHandlerFactoryAdded
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user