Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
7f473b82
Unverified
Commit
7f473b82
authored
2 months ago
by
Joost Lekkerkerker
Committed by
GitHub
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Prefer a local webhook for Overseerr (#134667)
parent
fea4a004
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/overseerr/__init__.py
+30
-15
30 additions, 15 deletions
homeassistant/components/overseerr/__init__.py
tests/components/overseerr/test_init.py
+22
-0
22 additions, 0 deletions
tests/components/overseerr/test_init.py
with
52 additions
and
15 deletions
homeassistant/components/overseerr/__init__.py
+
30
−
15
View file @
7f473b82
...
...
@@ -61,6 +61,21 @@ class OverseerrWebhookManager:
self
.
entry
=
entry
self
.
client
=
entry
.
runtime_data
.
client
@property
def
webhook_urls
(
self
)
->
list
[
str
]:
"""
Return webhook URLs.
"""
urls
=
[
async_generate_url
(
self
.
hass
,
self
.
entry
.
data
[
CONF_WEBHOOK_ID
],
prefer_external
=
external
)
for
external
in
(
False
,
True
)
]
res
=
[]
for
url
in
urls
:
if
url
not
in
res
:
res
.
append
(
url
)
return
res
async
def
register_webhook
(
self
)
->
None
:
"""
Register webhook.
"""
async_register
(
...
...
@@ -71,26 +86,26 @@ class OverseerrWebhookManager:
self
.
handle_webhook
,
allowed_methods
=
[
METH_POST
],
)
url
=
async_generate_url
(
self
.
hass
,
self
.
entry
.
data
[
CONF_WEBHOOK_ID
])
if
not
await
self
.
check_need_change
(
url
):
return
LOGGER
.
debug
(
"
Setting Overseerr webhook to %s
"
,
url
)
if
not
await
self
.
client
.
test_webhook_notification_config
(
url
,
JSON_PAYLOAD
):
LOGGER
.
debug
(
"
Failed to set Overseerr webhook
"
)
if
not
await
self
.
check_need_change
():
return
await
self
.
client
.
set_webhook_notification_config
(
enabled
=
True
,
types
=
REGISTERED_NOTIFICATIONS
,
webhook_url
=
url
,
json_payload
=
JSON_PAYLOAD
,
)
async
def
check_need_change
(
self
,
url
:
str
)
->
bool
:
for
url
in
self
.
webhook_urls
:
if
await
self
.
client
.
test_webhook_notification_config
(
url
,
JSON_PAYLOAD
):
LOGGER
.
debug
(
"
Setting Overseerr webhook to %s
"
,
url
)
await
self
.
client
.
set_webhook_notification_config
(
enabled
=
True
,
types
=
REGISTERED_NOTIFICATIONS
,
webhook_url
=
url
,
json_payload
=
JSON_PAYLOAD
,
)
return
LOGGER
.
error
(
"
Failed to set Overseerr webhook
"
)
async
def
check_need_change
(
self
)
->
bool
:
"""
Check if webhook needs to be changed.
"""
current_config
=
await
self
.
client
.
get_webhook_notification_config
()
return
(
not
current_config
.
enabled
or
current_config
.
options
.
webhook_url
!=
url
or
current_config
.
options
.
webhook_url
not
in
self
.
webhook_
url
s
or
current_config
.
options
.
json_payload
!=
json
.
loads
(
JSON_PAYLOAD
)
or
current_config
.
types
!=
REGISTERED_NOTIFICATIONS
)
...
...
This diff is collapsed.
Click to expand it.
tests/components/overseerr/test_init.py
+
22
−
0
View file @
7f473b82
...
...
@@ -128,3 +128,25 @@ async def test_webhook_failing_test(
mock_overseerr_client
.
test_webhook_notification_config
.
assert_called_once
()
mock_overseerr_client
.
set_webhook_notification_config
.
assert_not_called
()
async
def
test_prefer_internal_ip
(
hass
:
HomeAssistant
,
mock_config_entry
:
MockConfigEntry
,
mock_overseerr_client
:
AsyncMock
,
)
->
None
:
"""
Test the integration prefers internal IP.
"""
mock_overseerr_client
.
test_webhook_notification_config
.
return_value
=
False
hass
.
config
.
internal_url
=
"
http://192.168.0.123:8123
"
hass
.
config
.
external_url
=
"
https://www.example.com
"
await
hass
.
async_block_till_done
(
wait_background_tasks
=
True
)
await
setup_integration
(
hass
,
mock_config_entry
)
assert
(
mock_overseerr_client
.
test_webhook_notification_config
.
call_args_list
[
0
][
0
][
0
]
==
"
http://192.168.0.123:8123/api/webhook/test-webhook-id
"
)
assert
(
mock_overseerr_client
.
test_webhook_notification_config
.
call_args_list
[
1
][
0
][
0
]
==
"
https://www.example.com/api/webhook/test-webhook-id
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment