Skip to content

Commit 1ea6c16

Browse files
authored
Add set_power_handler and clarifications to event handlers
1 parent ba1eece commit 1ea6c16

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docs/Berry.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ If a precompiled bytecode (extension `.bec`) is present of more recent than the
265265

266266
You can easily create a complete Tasmota driver with Berry.
267267

268-
As a convenience, a skeleton class `Driver` is provided. A Driver responds to messages from Tasmota. For each message type, the method with the same name is called.
268+
As a convenience, a skeleton class `Driver` is provided. A Driver responds to messages from Tasmota. For each message type, the method with the same name is called. Actually you can register any class as a driver, it does not need to inherit from `Driver`; the call mechanism is based on names of methods that must match the name of the event to be called.
269+
270+
Driver methods are called with the following parameters: `f(cmd, idx, payload, raw)`. `cmd` is a string, `idx` an integer, `payload` a Berry object representation of the JSON in `payload` (if any) or `nil`, `raw` is a string. These parameters are meaninful to a small subset of events:
269271

270272
- `every_second()`: called every second
271273
- `every_100ms()`: called every 100ms (i.e. 10 times per second)
@@ -278,6 +280,7 @@ As a convenience, a skeleton class `Driver` is provided. A Driver responds to me
278280
- `button_pressed()`: called when a button is pressed
279281
- `web_sensor()`: send sensor information as JSON or HTML
280282
- `save_before_restart()`: called just before a restart
283+
- `set_power_handler(cmd, idx)`: called whenever a Power command is made. `idx` contains the index of the relay or light. `cmd` can be ignored.
281284
- `display()`: called by display driver with the following subtypes: `init_driver`, `model`, `dim`, `power`.
282285

283286
Then register the driver with `tasmota.add_driver(<driver>)`.

0 commit comments

Comments
 (0)