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

Toggle Block: command_state without interval should also be executed before command_on/off #2096

Open
tkapias opened this issue Oct 27, 2024 · 0 comments

Comments

@tkapias
Copy link

tkapias commented Oct 27, 2024

Issue

The documentation for this block is a bit misleading. It seems to read that if you omit to put an interval, the status check will be done at the time of the click to decide whether to do command_on or command_off.

But in fact the state is defined before that, by default or from a previous check and the command_state seems to be run after the toggle to validate the new state.

Context

I use many toggle blocks to control systemd services and I don't want to have 15 service checks running every x seconds, so I don't use intervals.

And I've always been a bit annoyed that if a service crashes a few seconds after launch I had to recheck manually because the toggle didn't take into account the change of state between 2 clicks.

To be sure I tested the block today with a simple grep/sed:

echo on > /tmp/test
[[block]]
block = "toggle"
format = "test"
command_state = "grep on /tmp/test"
command_on = "sed -i '1 s/^.*$/on/' /tmp/test"
command_off = "sed -i '1 s/^.*$/off/' /tmp/test"
state_on = "good"
state_off = "idle"

When the block is "on" and I manually write "off" in the test file, it should check again when I click before using command_on or command_on and stay on. But it's not the case and it switches to off.

Suggestions

When using "interval" I think that it's a good idea to use command_state only after a toggle, but with the "on click" behavior it should be checked before and after.

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

No branches or pull requests

1 participant