Add delay service

This commit is contained in:
Thomas Lovén 2021-02-09 23:15:04 +01:00
parent a28a53d34b
commit 0e85d2ef06
4 changed files with 19 additions and 8 deletions

View File

@ -325,13 +325,13 @@ data:
<data> <data>
``` ```
This can be used to send any command to a *device* by changing `command:` and appending any other options. This can be used to send any command to a *device* by setting `command:` to the service name and appending any other options.
E.g. the following two service calls will perform the same function: E.g. the following two service calls will perform the same function:
```yaml ```yaml
service: browser_mod.command service: browser_mod.command
data: data:
command: Toast command: toast
message: Hello World! message: Hello World!
service: browser_mod.toast service: browser_mod.toast
@ -350,6 +350,15 @@ data:
``` ```
This service can be used to call several services listed in the `commands:` parameter consecutively. This service can be used to call several services listed in the `commands:` parameter consecutively.
### - delay
```yaml
service: browser_mod.delay
data:
seconds: <seconds>
```
Do nothing for `<seconds>` seconds.
## Run a command from the frontend ## Run a command from the frontend
To run a command from the frontend, you can use the tap_action `fire-dom-event` with a `browser_mod` parameter. To run a command from the frontend, you can use the tap_action `fire-dom-event` with a `browser_mod` parameter.
E.g: E.g:
@ -463,7 +472,7 @@ This would replace the more-info dialogs of `sensor.sensor1` and `sensor.sensor2
### Where can I find my deviceID? ### Where can I find my deviceID?
The easiest way is to go to `developer-tools/service` and call the `browser_mod.debug` service. The easiest way is to go to `/developer-tools/service` and call the `browser_mod.debug` service.
But you can also find the device id on the `browser-player` card, if you added one to your lovelace config. But you can also find the device id on the `browser-player` card, if you added one to your lovelace config.

File diff suppressed because one or more lines are too long

View File

@ -34,4 +34,5 @@ USER_COMMANDS = [
"toast", "toast",
"commands", "commands",
"call_service", "call_service",
"delay",
] ]

View File

@ -44,7 +44,7 @@ class BrowserMod extends ext(BrowserModConnection, [
"color: green; font-weight: bold", ""); "color: green; font-weight: bold", "");
} }
msg_callback(msg) { async msg_callback(msg) {
const handlers = { const handlers = {
update: (msg) => this.update(msg), update: (msg) => this.update(msg),
debug: (msg) => this.debug(msg), debug: (msg) => this.debug(msg),
@ -74,14 +74,15 @@ class BrowserMod extends ext(BrowserModConnection, [
}, },
"call-service": (msg) => this.call_service(msg), "call-service": (msg) => this.call_service(msg),
"commands": (msg) => { "commands": async (msg) => {
for(const m of msg.commands) { for(const m of msg.commands) {
this.msg_callback(m); await this.msg_callback(m);
} }
}, },
"delay": async (msg) => await new Promise((resolve) => {window.setTimeout(resolve, msg.seconds*1000)}),
}; };
handlers[msg.command.replace("_","-")](msg); await handlers[msg.command.replace("_","-")](msg);
} }
debug(msg) { debug(msg) {