Skip to content
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

[RFC] thing actions #373

Open
wants to merge 1 commit into
base: 2.5.x
Choose a base branch
from
Open

[RFC] thing actions #373

wants to merge 1 commit into from

Conversation

t-8ch
Copy link
Member

@t-8ch t-8ch commented Jan 27, 2019

This implements support for thing actions, allowing rules to attach arbitrary parameters to rules.
Currently only the transitiontime on color channels is supported. Adding support for more converters is easily doable.
It allows rules to either supply a Map<String, Object> or use a typesafe builder to construct parameters.

Open points:

  • Should a converter ignore parameters it does not understand or error out?
  • is a Map<String, Object> the best way of representing a collection of parameters or would a datastructure validating all types be better.

(Untested, as I currently don't have access to a zigbee dongle.)

Signed-off-by: Thomas Weißschuh [email protected]

@t-8ch
Copy link
Member Author

t-8ch commented Feb 22, 2019

Another open point:
Should the transition time be configured with the internal X times "100ms" form or rather with a java.time.Duration?

@t-8ch
Copy link
Member Author

t-8ch commented Feb 22, 2019

@cdjackson @hsudbrock @puzzle-star What do you think?

Snippet I used to test:
(I am not sure why the typecast is needed there)

import org.openhab.binding.zigbee.action.ZigBeeThingActions

rule "test"
when
	Channel "zigbee:device:c9bb146b:00178801032372ed:00178801032372ED_11_color" triggered
then
	val zigbeeActions = getActions("zigbee", "zigbee:device:c9bb146b:00178801032372ed") as ZigBeeThingActions

	zigbeeActions.sendCommand("00178801032372ED_11_color", HSBType.GREEN, newHashMap("transitionTime" -> 500))
end

@t-8ch t-8ch force-pushed the thingactions branch 5 times, most recently from e30438a to d3f3a5b Compare February 23, 2019 14:10
@t-8ch
Copy link
Member Author

t-8ch commented Apr 18, 2019

Sorry for being annoying, but did you already find the time to look at this @cdjackson?

@cdjackson
Copy link
Contributor

This is where OH gets messy - we now have two concepts for changing configuration - configuration parameters, and now actions. How do we deal with this?

Personally, I would prefer to see configuration parameters configurable via rules rather than adding a new concept - I know you didn't add this concept, but we somehow have to deal with this. Either we make the system only use actions, or we make it use configuration, or we somehow need to combine the two (which seems messy).

Since transition time is already using configuration parameters, I think it's best not to add another concept, but the issue then is it can't be changed via rules unless we can add the ability to change parameters by rules in OH. Given that this problem comes up quite often, I think that's what should happen - but I don't know if it would be accepted.

@t-8ch
Copy link
Member Author

t-8ch commented Apr 19, 2019

I (mostly) agree. However only doing this via configuration parameters would be a bit messy if a parameter really only should apply to a single state change.

What do you think about having a generic mechanism to provide channel configuration (overrides) when executing thing actions?

  1. This would allow us to bridge the time until channel configurations can be changed from rules
  2. Provides a nice API for users that really only need a different configuration per-action
  3. Keeps things fairly consistent by reusing the names of the settings for both channel configuration parameters and per-action overrides

@cdjackson
Copy link
Contributor

cdjackson commented Apr 19, 2019 via email

@t-8ch
Copy link
Member Author

t-8ch commented Apr 19, 2019

It would mostly look like the current PR but instead of having an explicit enumeration of valid parameters it would be possible to pass any configuration parameter of the channel itself.

@cdjackson
Copy link
Contributor

cdjackson commented Apr 19, 2019 via email

@t-8ch
Copy link
Member Author

t-8ch commented Dec 20, 2019

I'd like to work again over the holidays.

We talked about having a way of overriding any configuration for single command.

This would be racy for configurations that are persisted in the ZigBee device itself.

Instead I think it should only be possible to override parameters that are sent directly inside the ZigBee command. (Like the transitionTime)

@t-8ch t-8ch force-pushed the thingactions branch 2 times, most recently from 86b8025 to c065d36 Compare December 23, 2019 15:06
@cdjackson
Copy link
Contributor

Instead I think it should only be possible to override parameters that are sent directly inside the ZigBee command. (Like the transitionTime).

Again, these are configured as configuration parameters. IMHO it should be possible to configure parameters in rules, and I thought that I saw something recently that indicated that was now (or may soon be) possible.

This is an issue that keeps coming up, and we keep adding bodges to allow people to configure parameters in rules - I think we should just allow parameters to be configured in rules.......

@kaikreuzer
Copy link
Member

I think we should just allow parameters to be configured in rules

This only makes sense to me, if we manage to finally implement eclipse-archived/smarthome#3484. Accessing thing handler configurations from rules is imho not really desirable.

But what @t-8ch asks for sounds indeed like a perfect match for thing actions. Any action/command that is parametrizable "directly inside the ZigBee command" can nicely be called from within rules and without the need to deal with any thing configurations or channels at all.

@cdjackson
Copy link
Contributor

cdjackson commented Dec 24, 2019 via email

@cdjackson
Copy link
Contributor

cdjackson commented Dec 24, 2019 via email

@t-8ch
Copy link
Member Author

t-8ch commented Dec 26, 2019

Even if the configuration could be changed from rules it will be impossible to change it only for one single command because commands are executed asynchronously via the commandScheduler.

(The exact usecase is to have a rule-triggered "sunrise" with a very long transitionTime. During the long transition it should still be possible to instantly control the light with the normal control mechanisms)

@cdjackson
Copy link
Contributor

cdjackson commented Dec 26, 2019 via email

@t-8ch
Copy link
Member Author

t-8ch commented Dec 26, 2019

Yeah, I also tried to push this, but this was fairly clearly rejected by OH itself.

IMHO by implementing parameters via thing actions now it should be fairly easy to later implement attributes if they are implemented in OH.

@cdjackson
Copy link
Contributor

cdjackson commented Dec 26, 2019 via email

@t-8ch t-8ch changed the base branch from master to 2.5.x December 26, 2019 17:11
@t-8ch
Copy link
Member Author

t-8ch commented Dec 26, 2019

Thanks!

The PR is now based on the 2.5.x branch.

The following questions are open IMO:

  • Is a Map<String, Object> sufficient or should there be a dedicated class that enforces correct parameters and their types?
  • Should parameters which are not used by a command be silently ignored or should they throw errors.
  • The docs want both non-static and static action methods. For new and old rules. Should compat with old rules be preserved?
    (Personally I don't know how the old ones look)

@cdjackson
Copy link
Contributor

Yeah, I also tried to push this, but this was fairly clearly rejected by OH itself.

I created an issue to discuss this point. openhab/openhab-core#1298

Is a Map<String, Object> sufficient or should there be a dedicated class that enforces correct parameters and their types?

I'd be tempted to use a custom class.

Should parameters which are not used by a command be silently ignored or should they throw errors.

I guess they can be ignored, but I would probably log an INFO or WARN so the user knows there's an issue (if they check the logs ;) ).

Should compat with old rules be preserved?

Personally, I'd be happy to ignore the old rules at this stage.

@t-8ch
Copy link
Member Author

t-8ch commented Dec 27, 2019

Updated the PR to include the latest feedback.

I am not sure in which java package to put the new functionality, though.

Currently the transition time is passed as an integer which signifies a multiple of 100ms, as ZSS handles it internally.
Personally I would prefer to have it as a java.time.Duration, wdyt?

So far only transition time for color channels is supported

Signed-off-by: Thomas Weißschuh <[email protected]>
@cdjackson
Copy link
Contributor

I think Duration is probably fine.

Looking through this, it still feels fundamentally wrong (don't worry - I'm not going to get into a big discussion here about that ;) ). We need to document this and I must admit I've not looked at actions much in the past but it seems that we now have two ways to do the same think.

If I want to turn a switch off, I use the standard send command to OFF, but if I want to turn off the same switch with a map of parameters, then I use the action. Can you provide some concrete examples of this (here for starters, but ultimately we should put it in the readme).

@t-8ch
Copy link
Member Author

t-8ch commented Dec 28, 2019

We need to document this and I must admit I've not looked at actions much in the past but it seems that we now have two ways to do the same think.

Yes, this has to be documented.

If I want to turn a switch off, I use the standard send command to OFF, but if I want to turn off the same switch with a map of parameters, then I use the action.

This is correct. The actions also support commands without parameters, so in cases where parameters are not always used, users can still stick to the actions for everything for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants