notify: add ability to notify using a remote action
Signed-off-by: Pieter Willekens <me@pataar.nl>
This commit is contained in:
parent
5d856b9c49
commit
21bb17743f
|
@ -1924,7 +1924,8 @@ events: *
|
|||
body: "Your printer status has changed to {event_name}"
|
||||
# The body of the notification. This option accepts Jinja2 templates.
|
||||
# You can use {event_name} to print the current event trigger name. And {event_args} for
|
||||
# the arguments that came with it.
|
||||
# the arguments that came with it. When using the notify functionality in a macro context, you can
|
||||
# use {event_message} to print out your message.
|
||||
title:
|
||||
# The optional title of the notification. Just as the body, this option accepts Jinja2 templates.
|
||||
attach:
|
||||
|
@ -1953,6 +1954,25 @@ url: tgram://{bottoken}/{ChatID}
|
|||
events: error
|
||||
body: {event_args[1].message}
|
||||
attach: http://192.168.1.100/webcam/?action=snapshot
|
||||
|
||||
[notifier gcode_telegram]
|
||||
url: tgram://{bottoken}/{ChatID}
|
||||
events: gcode
|
||||
body: {event_message}
|
||||
attach: http://192.168.1.100/webcam/?action=snapshot
|
||||
```
|
||||
|
||||
#### Notifying from Klipper
|
||||
It is possible to invoke your notifiers from the Klippy host, this can be done
|
||||
with a gcode_macro, such as:
|
||||
```ini
|
||||
# printer.cfg
|
||||
|
||||
[gcode_macro NOTIFY_FILAMENT_CHANGE]
|
||||
gcode:
|
||||
{action_call_remote_method("notify",
|
||||
name="telegram",
|
||||
message="Filament change needed!")}
|
||||
```
|
||||
|
||||
### `[simplyprint]`
|
||||
|
|
|
@ -35,6 +35,7 @@ class Notifier:
|
|||
prefix_sections = config.get_prefix_sections("notifier")
|
||||
|
||||
self.register_events(config)
|
||||
self.register_remote_actions()
|
||||
|
||||
for section in prefix_sections:
|
||||
cfg = config[section]
|
||||
|
@ -53,6 +54,16 @@ class Notifier:
|
|||
continue
|
||||
self.notifiers[notifier.get_name()] = notifier
|
||||
|
||||
def register_remote_actions(self):
|
||||
self.server.register_remote_method("notify", self.notify_action)
|
||||
|
||||
async def notify_action(self, name: str, message: str = ""):
|
||||
if name not in self.notifiers:
|
||||
raise self.server.error(f"Notifier '{name}' not found", 404)
|
||||
notifier = self.notifiers[name]
|
||||
|
||||
await notifier.notify("remote_action", [], message)
|
||||
|
||||
def register_events(self, config: ConfigHelper):
|
||||
|
||||
self.events["started"] = NotifierEvent(
|
||||
|
@ -145,10 +156,13 @@ class NotifierInstance:
|
|||
|
||||
self.apprise.add(self.url)
|
||||
|
||||
async def notify(self, event_name: str, event_args: List) -> None:
|
||||
async def notify(
|
||||
self, event_name: str, event_args: List, message: str = ""
|
||||
) -> None:
|
||||
context = {
|
||||
"event_name": event_name,
|
||||
"event_args": event_args
|
||||
"event_args": event_args,
|
||||
"event_message": message
|
||||
}
|
||||
|
||||
rendered_title = (
|
||||
|
|
Loading…
Reference in New Issue