-
Notifications
You must be signed in to change notification settings - Fork 1
README: thingManager example #17
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
README: thingManager example #17
Conversation
|
I suppose that the import declarations you removed was a remnant of a bad copy/paste. Yes, injection of the ThingManager (or any other openHAB value) into variable won't happen inside a method.
Does the fact that you tried to do this means that the documentation is not good enough ? |
This example just shows that the thingManager is accessible from script. |
Where is this stated exactly? For me this part of the documentation is clear, but it could be stated that thingManager serves only ot disable and enable things, while ruleManager serves only to disable and enable rules, and to And also including hyperlinks to the documentation of classes implementing thingManager, metadataRegistry, and ruleManager. E.g. in a table like https://github.com/openhab/openhab-docs/pull/2569/files . If access to metadataRegistry, ruleManager and thingManager are useful for OH automation, can you propose including them in one of the presets, offered by JSR 223-OH? For @InjectBinding I think it should be mentioned, that it is needed only for objects, which are not injected by default. Is this correct? I have not tried to use that helper.rules.eventinfo package, but e.g. src/helper/java/helper/rules/eventinfo/ItemCommand.java contains: @InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;
@InjectBinding protected @NonNullByDefault({}) Command command;and the bottom of https://www.openhab.org/docs/configuration/jsr223.html says for core.ItemCommandTrigger:
Another discrepancy, at https://www.openhab.org/docs/configuration/jsr223.html for core.ItemStateChangeTrigger is stated but helper.rules.eventinfo.ItemStateChange has: @InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;
@InjectBinding() protected @NonNullByDefault({}) State oldState;
@InjectBinding() protected @NonNullByDefault({}) State newState; |
Also an example with an helper.rules.eventinfo. object would be good. |
Good idea. I added a table like the one you mentioned, with a "purpose" column
I will make a PR to include the java223 bundle in openhab addon later this year.
In the documentation, I said it is for more control on the injection process, and preset. And the comments in the linked example try to explain it further. I though example was better suited for this. I'm open for a rewrite if you think it's not sufficient.
It's because it's two different things. On the page you mention, it is to define a trigger for a rule.
Yes it will work, but as indirectly stated in a comment in the InjectBindind example, when using InjectBinding like this, you automatically have the mandatory attribute to 'true' by default. I did this to fail faster if something is unexpected (for example, some openHAB change in the name of the injected value).
Same as above, it's two different things (trigger definition, and value injection in the resulting triggered action) |
I have one, but it could have a little boost in visibility by linking to it from other parts of the documentation. I will do so |
|
It is hard to find example for an I proposed at openhab/openhab-docs#2582 ⇔ https://deploy-preview-2582--openhab-docs-preview.netlify.app/docs/configuration/jsr223.html#triggertype-objects-all-jsr223-languages to document on the All openHAB Automation Add-Ons JSR223 page what the content of I thought until now that @InjectBinding is only handling data from From helper/rules/eventinfo/ItemStateChange.java: @InjectBinding(named = "event.itemName") protected @NonNullByDefault({}) String itemName;Is itemName taken from the org.openhab.core.automation.events.TimerEvent.getPayload(), from inputs.get('source'), or from where? I have not looked in the BindingInjector implementation,but I have the feeling this syntax with fullstop in Can this eventinfo/ItemStateChange annotation be used on a Java-method, which is part of SimpleRule, but has no Besides a core.ItemStateChangeTrigger receives a ItemStateChangedEvent and I guess core.ItemStateUpdateTrigger receives ItemStateUpdatedEvent. But here @ItemStateUpdateTrigger(itemName = Items.my_detector_item, state = OnOffType.ON.toString())
@ItemStateUpdateTrigger(itemName = Items.my_otherdetector_item, state = OnOffType.ON.toString())
public void myRule(ItemStateChange inputs) { // <-- HERE, strongly typed parameterI think it is mixed: an ItemStateUpdateTrigger supplies data for ItemStateChange handler, the parameter probably should be eventinfo.ItemStateUpdate. If a rule has triggers of two distinct types: import org.openhab.core.config.core.Configuration
import org.openhab.core.automation.module.script.rulesupport.shared.simple.SimpleRule
import org.openhab.core.automation.*
scriptExtension.importPreset("RuleSupport")
automationManager.addRule(new SimpleRule() {
@Override
Object execute(Action module, Map<String, ?> inputs) {
}
List<Trigger> triggers = [
TriggerBuilder.create().withId("trig1").withTypeUID("core.ItemStateChangeTrigger")
.withConfiguration(new Configuration([itemName: "d1"])).build(),
TriggerBuilder.create().withId("cr2").withTypeUID("core.ItemStateChangeTrigger")
.withConfiguration(new Configuration([itemName: "d2"])).build()
]
})Can as parameter values be used
I suggest removing all not needed |
I do have
Yes, objects from eventinfo package are lacking details. I will try to complete them.
Honestly, I don't really know who puts the data and when. And for rule action, I simply take them from the
The fullstop is a 'traversal' syntaxic sugar I added.
No, a SimpleRule designed by yourself is some java code who lives completely independently of the java223 bundle. No custom injection can occur, as openHAB calls the
Oops, indeed. Fixed.
No it probably won't work, because ItemStateChange and ItemStateUpdate have different mandatory parameters. The issue here is "mandatory". No individual trigger can provide those different parameters to the two EventInfo class at the same time.
Which ones are not needed ?
|
That is correct, I meant
I mean them. Currently the only thing which is guaranteed to fail, once openHAB cuts instances from the presets, or removes services ( |
I do not understand the above. In UI-based rules, where Java223 is only in charge for the action, openHAB calls the execute method directly. How can then the eventinfo.ItemStateChange() parameter type be used? |
I agree, I wasn't satisfied either when I wrote them.
When the action part of a rule is a script, openHAB asks the jsr223 bundle to run the script and passes the full context along (i.e. full context = "standard" binding value + event info, all in the same context map).
The openHAB context injection will occur at those moments:
For each of those cases, the bundle will try its best to chose what value to pass, and where, by using as a hint:
We can override this behaviour by using the InjectBinding annotation. On the contrary, when you define a SimpleRule by yourself and registers it to the RuleManager, the java223 bundle is NOT called when the action is executed. The execute method is directly called, with the raw binding map as a parameter.
The wrapped one-line script has in fact the same fields as the Java223Script base class (It is basically a copy). Injection occurs exactly the same. |
It is not good. Every class extending EventInfo is in Besides, this examples in README, appearing twice
That is what I am saying. When for some reason the service
will make sure, that the one-liner is not running anymore (cannot be recompiled anymore), even if Here a more practical example with disappearing services: when I ordinary shut down openhab, Java223 logs sometimes in openhab.log: Probably because the reference to the service ceased to exist.
What means This is not so correct. openhab/openhab-docs#2570 states already, that one and the same transformation cannot be executed at the same time, so this information can be removed from java223/README.md. I suggest you contribute to the discussion at openhab/openhab-docs#2573 about what can and cannot run in parallel. Then this information will be relevant for all OH Automation add-ons and can be removed from java223/README.md . As a side effect, what is correct statement on this parallelism in openHAB, or a false statement, will be reviewed by more people. |
Ok, done
Another subject: it would be interesting to know it openHAB is stopping to prevent (broken) code generation.
OK, I think that means we are not on the same page on this, because I think failing is good here.
If there is no InjectBinding annotation, then the value will be left null.
Excellent ! May I say "good riddance" ? 😂 Global documentation is a way better location for this 👍 |
I cannot get this example working, as it is.
This works:
If the
importwas necessary, thenimport org.openhab.core.thing.ThingManager;is correct andimport org.openhab.core.automation.ThingManager;provides errors.fails with
Also
produces
This again works:
That said, I do not know what exactly this example wants to demonstrate, as there are many possibilites.