-
-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a YAML file provider for semantic tags #3659
Conversation
We should probably go one step back and think about the whole design of the YAML files. I'll create a RFC for that this afternoon as a GitHUB discussion. |
I don't find it, did you create it? |
Sorry, I was a busy with real life issues. I'll try to write that this evening. With the concept I have in mind, the provider would not even need to handle anything except providing a DTO and registering itself with something similar to the |
Build failed because new dependencies with YAML libraries need to be added in each integration tests. |
8bc1921
to
fb3b205
Compare
fb3b205
to
18dd2c1
Compare
...ab.core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelListener.java
Outdated
Show resolved
Hide resolved
void addedModel(String modelName, List<? extends YamlElement> elements); | ||
|
||
void updatedModel(String modelName, List<? extends YamlElement> elements); | ||
|
||
void removedModel(String modelName, List<? extends YamlElement> elements); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the biggest problem I encountered.
@J-N-K : your suggestion was to use List<T>
as parameter type. Makes sense. Unfortunately, in this case, I am not able to call these methods in processWatchEvent
due to an error in Eclipse. Type argument is wrong and I don't know how to cast to the type expected by the compiler.
Advice would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@J-N-K : WDYT about that ?
....core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java
Outdated
Show resolved
Hide resolved
....core.semantics/src/main/java/org/openhab/core/semantics/model/yaml/YamlModelRepository.java
Outdated
Show resolved
Hide resolved
18dd2c1
to
5a3b3ac
Compare
Files in folder conf/tags are loaded by this provider. Related to openhab#3619 Signed-off-by: Laurent Garnier <[email protected]>
5a3b3ac
to
a6d93c1
Compare
Signed-off-by: Laurent Garnier <[email protected]>
A help is welcome to tell me what to add in itest.bndrun to make integration tests compile. Stuff related to YAML libraries has to be added. |
The watch service listener code will not work this way. I'll create a PR to your repo that makes it work. |
@J-N-K : any chance to have your help and review? |
Signed-off-by: Jan N. Klug <[email protected]>
See my commit, I didn't test it, but it should work (at least the structure should now be ok). |
Thank you @J-N-K . |
You can also do it per-file, that doesn't matter. The important thing is that you need to correctly resolve the path that comes from the watch service. |
Of course. I have not yet tested but will do in few minutes. |
In fact, it is not exactly per model but rather per directory. I will return to a simple map per file. |
It seem that e.g. the |
Yes and use the registry listener already available.
I am not sure about that... |
Unfortunately, a class cannot implement Another option is to have a multiple reference to providers in |
You can define a new interface for that |
Yes, I am doing something that should work... |
…Provider Signed-off-by: Laurent Garnier <[email protected]>
@J-N-K : I resolved the problem. Looks at the code please. I will resume my tests. |
@J-N-K : end of my tests, tests are successful. You can merge when you want. |
Would it be possible to use the uid as a key in the yaml file: So this tags:
# Example of a new equipment
- uid: Equipment_Curtain
label: Curtain
# Example of a new location
- uid: Location_Indoor_Room_HomeCinemaRoom
label: Home Cinema Room
description: The room containing my home cinema system.
synonyms:
- Home theater room
- TV room
- Movie room Will become this: tags:
# Example of a new equipment
Equipment_Curtain:
label: Curtain
# Example of a new location
Location_Indoor_Room_HomeCinemaRoom:
label: Home Cinema Room
description: The room containing my home cinema system.
synonyms:
- Home theater room
- TV room
- Movie room That way it would align with the suggestions I've made here |
I don't have a long history with YAML but I believe each element of a list must start with a -. So it would mean not using lists. |
I suggest you study this change after 4.1 is released, we don't have enough time now I believe. |
Correct, my suggestion is - instead of using a list - to use a mapping.
You can't immediately de serialize the loaded file but have to implement some additional logic. It's a trivial three to five liner - here in python # validate the file input
file = validate_file_structure(file)
# pull down the uids
objects = []
for uid, obj_definition in file.tags.items():
obj_def = obj_definition.copy()
obj_def['uid]'] = uid
objects.append(obj_def)
# now you can deserialize
deserialize_objects_from_dto(objects) Using the uid as a key in a mapping is not much easier to write and makes the format much more compact, it also saves you some ambiguity checks (e.g. for duplicate UIDs) because duplicate key is an invalid yaml. |
Please guys, nothing happened during 6 months and at 7 days before we freeze everything, you ask me "structural" changes ? If the syntax is changed after 4.1 is released, this is not a problem. I don't think users will create thousands of custom tags and the change will be very easy to do, we will explain it to users. |
I've only seen the provided example this morning, I believe it was not there before. I've made detailed suggestions for a file format 2 weeks ago and made suggestions on design guidelines.
I'm fine with that but then we have to communicate it accordingly and beforehand. |
"There is a possibility to create tags through this file format but this file format will change slightly with the next releases." |
While I agree that the format suggested by @spacemanspiff2007 is probably better, it is also more difficult to implement. Jackson can de-serialize a
is serialized into a |
I like this suggestion :) |
Just to nitpick - it's not wrong it's just not de-serializable into java objects out of the box. For this PR I have no objections, just that the upcoming file change is communicated with the feature announcement. |
...e.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java
Outdated
Show resolved
Hide resolved
...e.semantics/src/main/java/org/openhab/core/semantics/internal/SemanticsMetadataProvider.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Laurent Garnier <[email protected]>
It finally happens :) Thank you @J-N-K |
Related to openhab/openhab-core#3659 Signed-off-by: Laurent Garnier <[email protected]>
Related to openhab/openhab-core#3659 Signed-off-by: Laurent Garnier <[email protected]>
Files in folder conf/tags are loaded by this provider.
Related to #3619
Here is an example of file:
Signed-off-by: Laurent Garnier [email protected]