Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove background_task status #2491

Merged
merged 1 commit into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class HacsStatus:

startup: bool = True
new: bool = False
background_task: bool = False
reloading_data: bool = False
upgrading_all: bool = False

Expand Down Expand Up @@ -556,7 +555,6 @@ async def async_register_repository(
async def startup_tasks(self, _event=None) -> None:
"""Tasks that are started after setup."""
await self.async_set_stage(HacsStage.STARTUP)
self.status.background_task = True
self.status.startup = False

self.hass.bus.async_fire("hacs/status", {})
Expand All @@ -568,7 +566,6 @@ async def startup_tasks(self, _event=None) -> None:
if queue_task := self.tasks.get("prosess_queue"):
await queue_task.execute_task()

self.status.background_task = False
self.hass.bus.async_fire("hacs/status", {})

async def async_download_file(self, url: str) -> bytes | None:
Expand Down
1 change: 0 additions & 1 deletion custom_components/hacs/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def async_get_config_entry_diagnostics(
"stage": hacs.stage,
"version": hacs.version,
"disabled_reason": hacs.system.disabled_reason,
"background_task": hacs.status.background_task,
"new": hacs.status.new,
"startup": hacs.status.startup,
"categories": hacs.common.categories,
Expand Down
2 changes: 0 additions & 2 deletions custom_components/hacs/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def device_info(self) -> dict[str, any]:
@callback
def _update(self) -> None:
"""Update the sensor."""
if self.hacs.status.background_task:
return

repositories = [
repository
Expand Down
2 changes: 0 additions & 2 deletions custom_components/hacs/tasks/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ def get(self, slug: str) -> HacsTask | None:

async def async_execute_runtume_tasks(self) -> None:
"""Execute the the execute methods of each runtime task if the stage matches."""
self.hacs.status.background_task = True
await asyncio.gather(
*(
task.execute_task()
for task in self.tasks
if task.stages is not None and self.hacs.stage in task.stages
)
)
self.hacs.status.background_task = False
4 changes: 0 additions & 4 deletions custom_components/hacs/tasks/prosess_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ async def async_execute(self) -> None:
f"Can update {can_update} repositories, items in queue {self.hacs.queue.pending_tasks}",
)
if can_update != 0:
self.hacs.status.background_task = True
self.hass.bus.async_fire("hacs/status", {})
try:
await self.hacs.queue.execute(can_update)
except HacsExecutionStillInProgress:
pass
self.hacs.status.background_task = False
self.hass.bus.async_fire("hacs/status", {})
2 changes: 1 addition & 1 deletion custom_components/hacs/tasks/setup_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ async def hacs_status(hass, connection, msg):
msg["id"],
{
"startup": hacs.status.startup,
"background_task": hacs.status.background_task,
"background_task": False,
"lovelace_mode": hacs.core.lovelace_mode,
"reloading_data": hacs.status.reloading_data,
"upgrading_all": hacs.status.upgrading_all,
Expand Down
4 changes: 0 additions & 4 deletions custom_components/hacs/tasks/update_all_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ class Task(HacsTask):
async def async_execute(self) -> None:
"""Execute the task."""
self.hacs.log.debug("Starting recurring background task for all repositories")
self.hacs.status.background_task = True
self.hass.bus.async_fire("hacs/status", {})

for repository in self.hacs.repositories.list_all:
if repository.data.category in self.hacs.common.categories:
self.hacs.queue.add(repository.common_update())

self.hacs.status.background_task = False
await self.hacs.data.async_write()
self.hass.bus.async_fire("hacs/status", {})
self.hass.bus.async_fire("hacs/repository", {"action": "reload"})
self.hacs.log.debug("Recurring background task for all repositories done")
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Task(HacsTask):
async def async_execute(self) -> None:
"""Execute the task."""
self.hacs.log.debug("Starting recurring background task for installed repositories")
self.hacs.status.background_task = True
self.hass.bus.async_fire("hacs/status", {})

for repository in self.hacs.repositories.list_all:
if self.hacs.status.startup and repository.data.full_name == HacsGitHubRepo.INTEGRATION:
Expand All @@ -36,7 +34,5 @@ async def async_execute(self) -> None:
):
self.hacs.queue.add(repository.update_repository())

self.hacs.status.background_task = False
self.hass.bus.async_fire("hacs/status", {})
await self.hacs.data.async_write()
self.hacs.log.debug("Recurring background task for installed repositories done")
2 changes: 1 addition & 1 deletion custom_components/hacs/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, hacs: HacsBase):

async def async_write(self, force: bool = False) -> None:
"""Write content to the store files."""
if not force and (self.hacs.status.background_task or self.hacs.system.disabled):
if not force and self.hacs.system.disabled:
return

self.logger.debug("Saving data")
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ async def hacs(hass: HomeAssistant):
hacs_obj.core.ha_version = AwesomeVersion(HAVERSION)
hacs_obj.version = hacs_obj.integration.version
hacs_obj.configuration.token = TOKEN
hacs_obj.status.background_task = False

## New GitHub client
hacs_obj.githubapi = GitHubAPI(
Expand Down
1 change: 0 additions & 1 deletion tests/hacsbase/test_hacsbase_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async def test_hacs_data_async_write1(hacs, repository):
@pytest.mark.asyncio
async def test_hacs_data_async_write2(hacs):
data = HacsData(hacs)
hacs.status.background_task = False
hacs.system.disabled_reason = None
hacs.repositories = HacsRepositories()
await data.async_write()
Expand Down
36 changes: 0 additions & 36 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,42 +90,6 @@ async def test_sensor_update_event(hacs: HacsBase, hass: HomeAssistant):
assert sensor.state == 1


@pytest.mark.asyncio
async def test_sensor_update_event_background_task(hacs: HacsBase, hass: HomeAssistant):
sensor = await sensor_setup(hacs, hass)

repository = HacsIntegrationRepository(hacs, "test/one")
repository.data.update_data(
{
"id": "123",
"installed": True,
"installed_version": "1",
"last_version": "2",
}
)
hacs.repositories.register(repository)

repository = HacsIntegrationRepository(hacs, "test/two")
repository.data.update_data(
{
"id": "321",
"installed": True,
"installed_version": "1",
"last_version": "1",
}
)
hacs.repositories.register(repository)

hacs.common.categories = {"integration"}
assert sensor.state is None
hacs.status.background_task = True

hass.bus.async_fire("hacs/status", {})

await hass.async_block_till_done()
assert sensor.state is None


@pytest.mark.asyncio
async def test_sensor_update_manual(hacs: HacsBase, hass: HomeAssistant):
sensor = await sensor_setup(hacs, hass)
Expand Down