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

[items] Item: Add sendIncreaseCommand/sendDecreaseCommand methods #371

Merged
merged 8 commits into from
Sep 18, 2024

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Aug 6, 2024

Closes #369.

Also:

  • Make Item::getToggleState method private.
  • Adjust Item::getToggleState/Item::sendToggleCommand method to Item.type changes from a previous PR
  • Use brightness value of Color Items for Item::numericState.

@florian-h05
Copy link
Contributor Author

@mueller-ma You can download the dist-without-license artifact from https://github.com/openhab/openhab-js/actions/runs/10271819868?pr=371 and put the openhab.js file contained in the ZIP into the $OPENHAB_CONF/automation/js/node_modules folder.
Then disable injection caching in the add-on settings and you can try out the new methods.

WRT to naming: increaseValueTo and decreaseValueTo are short, but not really in line with sendCommand, sendToggleCommand, sendCommandIfDifferent. But sendIncreaseValueToCommand are too long?

@mueller-ma
Copy link
Member

What about sendIncreaseCommand()?

@florian-h05
Copy link
Contributor Author

Sounds good - have you been able to give this PR a try?

@mueller-ma
Copy link
Member

I tested sendIncreaseCommand(10) on a Dimmer item that was at 100 and it got decreased to 10. How can I help to debug this?

@florian-h05
Copy link
Contributor Author

I cannot reproduce this issue with basic Dimmer and Number Items (means no metadata, just a Item with a name).

If you have changed the dimmer to 100 and sendIncreaseCommand right afterwards, i.e. by having a script that does these two steps after each other, it may be the case that a wrong command is sent because the Item state hasn't been updated yet.

This works just fine for me:

var item = items.test_dimmer

item.sendCommand(100)

java.lang.Thread.sleep(500)
item.sendIncreaseCommand(10)

java.lang.Thread.sleep(500)
item.sendDecreaseCommand(15)

java.lang.Thread.sleep(500)
item.sendIncreaseCommand(50)

java.lang.Thread.sleep(500)
item.sendIncreaseCommand(10)

Note the sleeps to avoid the above mentioned issue.

@florian-h05
Copy link
Contributor Author

You can enable debug logging (just added it) by setting the log level of org.openhab.automation.openhab-js.items to DEBUG.

@florian-h05 florian-h05 added the enhancement New feature or request label Sep 15, 2024
@florian-h05 florian-h05 modified the milestone: to be released Sep 15, 2024
@florian-h05
Copy link
Contributor Author

florian-h05 commented Sep 16, 2024

@mueller-ma Let me know when you have been able to test it again.
You can find the latest build artifact here: https://github.com/openhab/openhab-js/actions/runs/10884537238/artifacts/1937578562

@mueller-ma
Copy link
Member

Now it seems to work. Maybe I did something wrong with downloading the library the first time.

Thank you for this PR 👍

@florian-h05 florian-h05 marked this pull request as ready for review September 17, 2024 16:11
@florian-h05 florian-h05 requested a review from a team as a code owner September 17, 2024 16:11
Signed-off-by: Florian Hotze <[email protected]>
Signed-off-by: Florian Hotze <[email protected]>
@florian-h05 florian-h05 merged commit 2348409 into openhab:main Sep 18, 2024
4 checks passed
@florian-h05 florian-h05 deleted the item-deincrease-value-to branch September 18, 2024 15:39
@florian-h05 florian-h05 added this to the to be released milestone Sep 18, 2024
@florian-h05 florian-h05 changed the title [items] Item: Add increaseValueTo/decreaseValueTo methods [items] Item: Add sendIncreaseCommand/sendDecreaseCommand methods Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to send Item updates only in some cases
2 participants