mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
Merge pull request #591 from Schlump/main
Add Pushover device support - thanks @Schlump 🙏
This commit is contained in:
@@ -404,6 +404,28 @@
|
|||||||
"string": "Your Pushover APP Token."
|
"string": "Your Pushover APP Token."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": "DEVICE_NAME",
|
||||||
|
"type": "text",
|
||||||
|
"default_value": "DEVICE_NAME",
|
||||||
|
"options": [],
|
||||||
|
"localized": [
|
||||||
|
"name",
|
||||||
|
"description"
|
||||||
|
],
|
||||||
|
"name": [
|
||||||
|
{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string": "Pushover Device name (not required)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": [
|
||||||
|
{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string": "When specifying a device name, notifications will be exclusively sent to the device."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,18 +71,28 @@ def send(text):
|
|||||||
|
|
||||||
user_key = get_setting_value("PUSHOVER_USER_KEY")
|
user_key = get_setting_value("PUSHOVER_USER_KEY")
|
||||||
app_token = get_setting_value("PUSHOVER_APP_TOKEN")
|
app_token = get_setting_value("PUSHOVER_APP_TOKEN")
|
||||||
|
device_name = (
|
||||||
|
None
|
||||||
|
if get_setting_value("PUSHOVER_DEVICE_NAME") == "DEVICE_NAME"
|
||||||
|
else get_setting_value("PUSHOVER_DEVICE_NAME")
|
||||||
|
)
|
||||||
|
|
||||||
mylog("verbose", f'[{pluginName}] PUSHOVER_USER_KEY: "{hide_string(user_key)}"')
|
mylog("verbose", f'[{pluginName}] PUSHOVER_USER_KEY: "{hide_string(user_key)}"')
|
||||||
mylog("verbose", f'[{pluginName}] PUSHOVER_APP_TOKEN: "{hide_string(app_token)}"')
|
mylog("verbose", f'[{pluginName}] PUSHOVER_APP_TOKEN: "{hide_string(app_token)}"')
|
||||||
|
|
||||||
|
data = {"token": app_token, "user": user_key, "message": text}
|
||||||
|
# Add device_name to the data dictionary only if it is not None
|
||||||
|
if device_name:
|
||||||
|
data["device"] = device_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.post(
|
response = requests.post("https://api.pushover.net/1/messages.json", data=data)
|
||||||
"https://api.pushover.net/1/messages.json",
|
|
||||||
data={"token": app_token, "user": user_key, "message": text},
|
# Update response_status_code with the actual status code from the response
|
||||||
)
|
response_status_code = response.status_code
|
||||||
|
|
||||||
# Check if the request was successful (status code 200)
|
# Check if the request was successful (status code 200)
|
||||||
if response.status_code == 200:
|
if response_status_code == 200:
|
||||||
response_text = response.text # This captures the response body/message
|
response_text = response.text # This captures the response body/message
|
||||||
else:
|
else:
|
||||||
response_text = json.dumps(response.text)
|
response_text = json.dumps(response.text)
|
||||||
|
|||||||
Reference in New Issue
Block a user