Limit Github event subscription if polling is disabled (#78662)

pull/78682/head
Joakim Sørensen 2022-09-18 11:40:42 +02:00 committed by GitHub
parent 69c5d910d4
commit 87f8ebceb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -38,7 +38,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
await coordinator.async_config_entry_first_refresh()
await coordinator.subscribe()
if not entry.pref_disable_polling:
await coordinator.subscribe()
hass.data[DOMAIN][repository] = coordinator

View File

@ -1,7 +1,7 @@
"""Test the GitHub init file."""
from pytest import LogCaptureFixture
from homeassistant.components.github.const import CONF_REPOSITORIES
from homeassistant.components.github import CONF_REPOSITORIES
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -44,3 +44,42 @@ async def test_device_registry_cleanup(
)
assert len(devices) == 0
async def test_subscription_setup(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test that we setup event subscription."""
mock_config_entry.options = {CONF_REPOSITORIES: ["home-assistant/core"]}
mock_config_entry.pref_disable_polling = False
await setup_github_integration(hass, mock_config_entry, aioclient_mock)
assert (
"https://api.github.com/repos/home-assistant/core/events" in x[1]
for x in aioclient_mock.mock_calls
)
async def test_subscription_setup_polling_disabled(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test that we do not setup event subscription if polling is disabled."""
mock_config_entry.options = {CONF_REPOSITORIES: ["home-assistant/core"]}
mock_config_entry.pref_disable_polling = True
await setup_github_integration(hass, mock_config_entry, aioclient_mock)
assert (
"https://api.github.com/repos/home-assistant/core/events" not in x[1]
for x in aioclient_mock.mock_calls
)
# Prove that we subscribed if the user enabled polling again
mock_config_entry.pref_disable_polling = False
assert await hass.config_entries.async_reload(mock_config_entry.entry_id)
await hass.async_block_till_done()
assert (
"https://api.github.com/repos/home-assistant/core/events" in x[1]
for x in aioclient_mock.mock_calls
)