Skip to content

Commit

Permalink
Merge branch 'main' into remove_netdaemon
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Apr 11, 2024
2 parents 4158d1d + cf80a76 commit 7d109f8
Show file tree
Hide file tree
Showing 49 changed files with 272 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
files: ^((custom_components|script|tests)/.+)?[^/]+\.py$

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.6
hooks:
- id: codespell
stages: [manual]
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/pull_requests_labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
types:
- labeled
- opened
- synchronize
- unlabeled
branches:
- main
Expand All @@ -19,9 +21,10 @@ jobs:
uses: actions/checkout@v4.1.1

- name: Check the labels
uses: ludeeus/action-require-labels@1.0.0
uses: ludeeus/action-require-labels@1.1.0
with:
labels: >-
Breaking Change, Experimental, pr: new-feature,
pr: enhancement, pr: refactor, pr: bugfix,
pr: dependency-update
pr: dependency-update, pr: action, pr: test,
pr: repository
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ jobs:
runs-on: ubuntu-latest
name: Trigger Discord notification when jobs fail
needs: ["preflight","validate-hassfest", "validate-hacs", "validate-homeassistant"]
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') && github.event_name == 'schedule' }}
steps:
- name: Send notification
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') && github.event_name == 'schedule' }}
run: |
curl \
-H "Content-Type: application/json" \
Expand Down
44 changes: 21 additions & 23 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ async def async_initialize_integration(
hacs.enable_hacs()

if config is not None:
if DOMAIN not in config:
return True
if hacs.configuration.config_type == ConfigurationType.CONFIG_ENTRY:
return True
hacs.configuration.update_from_dict(
{
"config_type": ConfigurationType.YAML,
Expand Down Expand Up @@ -219,24 +215,26 @@ async def async_try_startup(_=None):

async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
"""Set up this integration using yaml."""
if DOMAIN in config:
async_create_issue(
hass,
DOMAIN,
"deprecated_yaml_configuration",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml_configuration",
learn_more_url="https://hacs.xyz/docs/configuration/options",
)
LOGGER.warning(
"YAML configuration of HACS is deprecated and will be "
"removed in version 2.0.0, there will be no automatic "
"import of this. "
"Please remove it from your configuration, "
"restart Home Assistant and use the UI to configure it instead."
)
if DOMAIN not in config:
return True

async_create_issue(
hass,
DOMAIN,
"deprecated_yaml_configuration",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml_configuration",
learn_more_url="https://hacs.xyz/docs/configuration/options",
)
LOGGER.warning(
"YAML configuration of HACS is deprecated and will be "
"removed in version 2.0.0, there will be no automatic "
"import of this. "
"Please remove it from your configuration, "
"restart Home Assistant and use the UI to configure it instead."
)
return await async_initialize_integration(hass=hass, config=config)


Expand All @@ -259,7 +257,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
# Clear out pending queue
hacs.queue.clear()

for task in hacs.recuring_tasks:
for task in hacs.recurring_tasks:
# Cancel all pending tasks
task()

Expand Down
30 changes: 16 additions & 14 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
HacsRepositoryExistException,
HomeAssistantCoreRepositoryException,
)
from .repositories import RERPOSITORY_CLASSES
from .repositories import REPOSITORY_CLASSES
from .utils.decode import decode_content
from .utils.json import json_loads
from .utils.logger import LOGGER
Expand Down Expand Up @@ -373,7 +373,7 @@ def __init__(self) -> None:
self.configuration = HacsConfiguration()
self.core = HacsCore()
self.log = LOGGER
self.recuring_tasks: list[Callable[[], None]] = []
self.recurring_tasks: list[Callable[[], None]] = []
self.repositories = HacsRepositories()
self.status = HacsStatus()
self.system = HacsSystem()
Expand Down Expand Up @@ -553,7 +553,7 @@ async def async_register_repository(
):
raise AddonRepositoryException()

if category not in RERPOSITORY_CLASSES:
if category not in REPOSITORY_CLASSES:
self.log.warning(
"%s is not a valid repository category, %s will not be registered.",
category,
Expand All @@ -564,7 +564,7 @@ async def async_register_repository(
if (renamed := self.common.renamed_repositories.get(repository_full_name)) is not None:
repository_full_name = renamed

repository: HacsRepository = RERPOSITORY_CLASSES[category](self, repository_full_name)
repository: HacsRepository = REPOSITORY_CLASSES[category](self, repository_full_name)
if check:
try:
await repository.async_registration(ref)
Expand Down Expand Up @@ -627,59 +627,61 @@ async def startup_tasks(self, _=None) -> None:
break

if not self.configuration.experimental:
self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_update_downloaded_repositories, timedelta(hours=48)
)
)
self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_update_all_repositories,
timedelta(hours=96),
)
)
else:
self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_load_hacs_from_github,
timedelta(hours=48),
)
)

self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_update_downloaded_custom_repositories, timedelta(hours=48)
)
)

self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_get_all_category_repositories, timedelta(hours=6)
)
)

self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_check_rate_limit, timedelta(minutes=5)
)
)
self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_prosess_queue, timedelta(minutes=10)
)
)

self.recuring_tasks.append(
self.recurring_tasks.append(
self.hass.helpers.event.async_track_time_interval(
self.async_handle_critical_repositories, timedelta(hours=6)
)
)

self.hass.bus.async_listen_once(
unsub = self.hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_FINAL_WRITE, self.data.async_force_write
)
if config_entry := self.configuration.config_entry:
config_entry.async_on_unload(unsub)

self.log.debug("There are %s scheduled recurring tasks", len(self.recuring_tasks))
self.log.debug("There are %s scheduled recurring tasks", len(self.recurring_tasks))

self.status.startup = False
self.async_dispatch(HacsDispatchEvent.STATUS, {})
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .template import HacsTemplateRepository
from .theme import HacsThemeRepository

RERPOSITORY_CLASSES: dict[HacsCategory, HacsRepository] = {
REPOSITORY_CLASSES: dict[HacsCategory, HacsRepository] = {
HacsCategory.THEME: HacsThemeRepository,
HacsCategory.INTEGRATION: HacsIntegrationRepository,
HacsCategory.PYTHON_SCRIPT: HacsPythonScriptRepository,
Expand Down
6 changes: 0 additions & 6 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,6 @@ async def common_registration(self) -> None:
self.data.last_updated = self.repository_object.attributes.get("pushed_at", 0)
self.data.last_fetched = datetime.utcnow()

# Set topics
self.data.topics = self.data.topics

# Set description
self.data.description = self.data.description

@concurrent(concurrenttasks=10, backoff_time=5)
async def common_update(self, ignore_issues=False, force=False, skip_releases=False) -> bool:
"""Common information update steps of the repository."""
Expand Down
7 changes: 6 additions & 1 deletion custom_components/hacs/system_health.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Provide info to system health."""
from typing import Any

from aiogithubapi.common.const import BASE_API_URL
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback
Expand All @@ -17,8 +19,11 @@ def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegi
register.async_register_info(system_health_info, "/hacs")


async def system_health_info(hass):
async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
"""Get info for the info page."""
if DOMAIN not in hass.data:
return {"Disabled": "HACS is not loaded, but HA still requests this information..."}

hacs: HacsBase = hass.data[DOMAIN]
response = await hacs.githubapi.rate_limit()

Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/websocket/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def hacs_repositories_clear_new(
connection: websocket_api.ActiveConnection,
msg: dict[str, Any],
) -> None:
"""Clear new repositories for spesific categories."""
"""Clear new repositories for specific categories."""
hacs: HacsBase = hass.data.get(DOMAIN)

if repo := msg.get("repository"):
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r requirements_base.txt
asynctest==0.13.0
fnv-hash-fast==0.5.0
freezegun==1.4.0
home-assistant-frontend
homeassistant
janus==1.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _sort_list(entry):
value = data[key]
if key in to_remove:
continue
elif isinstance(value, (str, bool, int, NoneType)):
elif isinstance(value, (str, bool, int, float, NoneType)):
returndata[key] = value
elif isinstance(value, dict):
returndata[key] = recursive_remove_key(
Expand Down
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Set up some common test helper things."""
# pytest: disable=protected-access
from . import patch_time # noqa: F401, isort:skip
import asyncio
from collections import OrderedDict
from dataclasses import asdict
Expand All @@ -12,6 +13,7 @@
from unittest.mock import MagicMock, patch

from awesomeversion import AwesomeVersion
import freezegun
from homeassistant import loader
from homeassistant.auth.models import Credentials
from homeassistant.auth.providers.homeassistant import HassAuthProvider
Expand Down Expand Up @@ -75,6 +77,12 @@
asyncio.sleep = lambda _: _sleep(0)


@pytest.fixture(autouse=True)
def time_freezer():
with freezegun.freeze_time("2019-02-26T15:02:39Z"):
yield


@pytest.fixture(autouse=True)
def set_request_context(request: pytest.FixtureRequest):
"""Set request context for every test."""
Expand Down Expand Up @@ -105,7 +113,7 @@ def event_loop():


@pytest.fixture
def hass(event_loop, tmpdir, check_report_issue: None):
def hass(time_freezer, event_loop, tmpdir, check_report_issue: None):
"""Fixture to provide a test instance of Home Assistant."""

def exc_handle(loop, context):
Expand Down Expand Up @@ -257,7 +265,7 @@ async def assert_hacs_data(
),
**(additional or {}),
},
("categories", "config_entry_id", "device_id", "labels", "last_fetched"),
("categories", "config_entry_id", "device_id", "labels"),
)
),
filename,
Expand Down
19 changes: 19 additions & 0 deletions tests/output/proxy_calls.json
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,25 @@
"https://api.github.com/repos/hacs/integration/git/trees/main": 1,
"https://api.github.com/repos/hacs/integration/releases": 1
},
"tests/test_system_health.py::test_system_health": {
"https://api.github.com": 1,
"https://api.github.com/rate_limit": 1,
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
"https://api.github.com/repos/hacs/integration/git/trees/main": 1,
"https://api.github.com/repos/hacs/integration/releases": 1,
"https://data-v2.hacs.xyz/data.json": 1,
"https://github.com/": 1,
"https://raw.githubusercontent.com/hacs/integration/main/hacs.json": 1
},
"tests/test_system_health.py::test_system_health_after_unload": {
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
"https://api.github.com/repos/hacs/integration/contents/hacs.json": 1,
"https://api.github.com/repos/hacs/integration/git/trees/main": 1,
"https://api.github.com/repos/hacs/integration/releases": 1
},
"tests/utils/test_path.py::test_is_safe": {
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
Expand Down
26 changes: 26 additions & 0 deletions tests/patch_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Patch time related functions.
Copied from Home Assistant Core.
"""
from __future__ import annotations

import datetime
import time

from homeassistant import runner, util
from homeassistant.util import dt as dt_util


def _utcnow() -> datetime.datetime:
"""Make utcnow patchable by freezegun."""
return datetime.datetime.now(tz=datetime.UTC)


def _monotonic() -> float:
"""Make monotonic patchable by freezegun."""
return time.monotonic()


dt_util.utcnow = _utcnow # type: ignore[assignment]
util.utcnow = _utcnow # type: ignore[assignment]
runner.monotonic = _monotonic # type: ignore[assignment]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"installed": true,
"installed_commit": "7fd1a60",
"last_commit": "7fd1a60",
"last_fetched": 1551193359.0,
"last_updated": "2011-01-26T19:06:43Z",
"last_version": "1.0.0",
"published_tags": [
Expand Down Expand Up @@ -42,6 +43,7 @@
"full_name": "hacs/integration",
"id": "172733314",
"installed": true,
"last_fetched": 1551193359.0,
"last_updated": "2023-11-18T21:22:03Z",
"manifest_name": "HACS",
"open_issues": 2,
Expand Down

0 comments on commit 7d109f8

Please sign in to comment.