Add delay service
This commit is contained in:
parent
a28a53d34b
commit
0e85d2ef06
15
README.md
15
README.md
@ -325,13 +325,13 @@ 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:
|
||||
|
||||
```yaml
|
||||
service: browser_mod.command
|
||||
data:
|
||||
command: Toast
|
||||
command: toast
|
||||
message: Hello World!
|
||||
|
||||
service: browser_mod.toast
|
||||
@ -350,6 +350,15 @@ data:
|
||||
```
|
||||
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
|
||||
To run a command from the frontend, you can use the tap_action `fire-dom-event` with a `browser_mod` parameter.
|
||||
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?
|
||||
|
||||
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.
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -34,4 +34,5 @@ USER_COMMANDS = [
|
||||
"toast",
|
||||
"commands",
|
||||
"call_service",
|
||||
"delay",
|
||||
]
|
||||
|
@ -44,7 +44,7 @@ class BrowserMod extends ext(BrowserModConnection, [
|
||||
"color: green; font-weight: bold", "");
|
||||
}
|
||||
|
||||
msg_callback(msg) {
|
||||
async msg_callback(msg) {
|
||||
const handlers = {
|
||||
update: (msg) => this.update(msg),
|
||||
debug: (msg) => this.debug(msg),
|
||||
@ -74,14 +74,15 @@ class BrowserMod extends ext(BrowserModConnection, [
|
||||
},
|
||||
|
||||
"call-service": (msg) => this.call_service(msg),
|
||||
"commands": (msg) => {
|
||||
"commands": async (msg) => {
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user