Skip to content

Commit

Permalink
Cleanup unused constants (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Dec 26, 2021
1 parent 46bed88 commit 33d7f0c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 32 deletions.
7 changes: 4 additions & 3 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
from homeassistant.core import HomeAssistant
from homeassistant.loader import Integration

from .const import REPOSITORY_HACS_DEFAULT, SEMAPHORE_DEFAULT, TV
from .const import SEMAPHORE_DEFAULT, TV
from .enums import (
ConfigurationType,
HacsCategory,
HacsDisabledReason,
HacsGitHubRepo,
HacsStage,
LovelaceMode,
)
Expand Down Expand Up @@ -434,7 +435,7 @@ async def async_github_get_hacs_default_file(self, filename: str) -> dict[str, A
"""Get the content of a default file."""
response = await self.async_github_api_method(
method=self.githubapi.repos.contents.get,
repository=REPOSITORY_HACS_DEFAULT,
repository=HacsGitHubRepo.DEFAULT,
path=filename,
)
return json.loads(decode_content(response.data.content))
Expand Down Expand Up @@ -606,7 +607,7 @@ async def recurring_tasks_installed(self, _notarealarg=None):
self.hass.bus.async_fire("hacs/status", {})

for repository in self.repositories.list_all:
if self.status.startup and repository.data.full_name == "hacs/integration":
if self.status.startup and repository.data.full_name == HacsGitHubRepo.INTEGRATION:
continue
if repository.data.installed and repository.data.category in self.common.categories:
self.queue.add(self.async_semaphore_wrapper(repository.update_repository))
Expand Down
20 changes: 0 additions & 20 deletions custom_components/hacs/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@

from aiogithubapi.common.const import ACCEPT_HEADERS

NAME_LONG = "HACS (Home Assistant Community Store)"
NAME_SHORT = "HACS"
DOMAIN = "hacs"
CLIENT_ID = "395a8e669c5de9f7c6e8"
MINIMUM_HA_VERSION = "0.0.0"
PROJECT_URL = "https://github.com/hacs/integration/"


ISSUE_URL = f"{PROJECT_URL}issues"
DOMAIN_DATA = f"{NAME_SHORT.lower()}_data"

TV = TypeVar("TV")

PACKAGE_NAME = "custom_components.hacs"

REPOSITORY_HACS_DEFAULT = "hacs/default"
REPOSITORY_HACS_INTEGRATION = "hacs/integration"

SEMAPHORE_DEFAULT = 15

PLATFORMS = ["sensor"]
Expand All @@ -30,20 +21,9 @@
"Accept": ACCEPT_HEADERS["preview"],
}

IFRAME = {
"title": "HACS",
"icon": "hacs:hacs",
"url": "/community_overview",
"path": "community",
"require_admin": True,
}

VERSION_STORAGE = "6"
STORENAME = "hacs"

# Messages
NO_ELEMENTS = "No elements to show, open the store to install some awesome stuff."

STARTUP = """
-------------------------------------------------------------------
HACS (Home Assistant Community Store)
Expand Down
7 changes: 7 additions & 0 deletions custom_components/hacs/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from enum import Enum


class HacsGitHubRepo(str, Enum):
"""HacsGitHubRepo."""

DEFAULT = "hacs/default"
INTEGRATION = "hacs/integration"


class HacsCategory(str, Enum):
APPDAEMON = "appdaemon"
INTEGRATION = "integration"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/repositories/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from homeassistant.loader import async_get_custom_components

from ..enums import HacsCategory
from ..enums import HacsCategory, HacsGitHubRepo
from ..exceptions import HacsException
from ..utils import filters
from ..utils.information import get_integration_manifest
Expand Down Expand Up @@ -35,7 +35,7 @@ def localpath(self):
async def async_post_installation(self):
"""Run post installation steps."""
if self.data.config_flow:
if self.data.full_name != "hacs/integration":
if self.data.full_name != HacsGitHubRepo.INTEGRATION:
await self.reload_custom_components()
if self.data.first_install:
self.pending_restart = False
Expand Down
8 changes: 4 additions & 4 deletions custom_components/hacs/tasks/load_hacs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from homeassistant.core import HomeAssistant

from ..base import HacsBase
from ..enums import HacsDisabledReason, HacsStage
from ..enums import HacsDisabledReason, HacsGitHubRepo, HacsStage
from ..exceptions import HacsException
from ..utils.register_repository import register_repository
from .base import HacsTask
Expand All @@ -23,12 +23,12 @@ class Task(HacsTask):
async def async_execute(self) -> None:
"""Execute the task."""
try:
repository = self.hacs.repositories.get_by_full_name("hacs/integration")
repository = self.hacs.repositories.get_by_full_name(HacsGitHubRepo.INTEGRATION)
if repository is None:
await register_repository(
self.hacs, "hacs/integration", "integration", default=True
self.hacs, HacsGitHubRepo.INTEGRATION, "integration", default=True
)
repository = self.hacs.repositories.get_by_full_name("hacs/integration")
repository = self.hacs.repositories.get_by_full_name(HacsGitHubRepo.INTEGRATION)
if repository is None:
raise HacsException("Unknown error")
repository.data.installed = True
Expand Down
3 changes: 2 additions & 1 deletion custom_components/hacs/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.core import callback

from ..base import HacsBase
from ..enums import HacsGitHubRepo
from ..repositories.base import HacsManifest
from .logger import getLogger
from .register_repository import register_repository
Expand Down Expand Up @@ -226,7 +227,7 @@ def async_restore_repository(self, entry, repository_data):
if repository.data.installed:
repository.status.first_install = False

if full_name == "hacs/integration":
if full_name == HacsGitHubRepo.INTEGRATION:
repository.data.installed_version = self.hacs.version
repository.data.installed = True

Expand Down
3 changes: 2 additions & 1 deletion custom_components/hacs/utils/register_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from aiogithubapi import AIOGitHubAPIException

from ..enums import HacsGitHubRepo
from ..exceptions import (
HacsException,
HacsExpectedException,
Expand All @@ -28,7 +29,7 @@ async def register_repository(
):
"""Register a repository."""
if full_name in hacs.common.skip:
if full_name != "hacs/integration":
if full_name != HacsGitHubRepo.INTEGRATION:
raise HacsExpectedException(f"Skipping {full_name}")

if category not in RERPOSITORY_CLASSES:
Expand Down
3 changes: 2 additions & 1 deletion tests/hacsbase/test_hacsbase_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from custom_components.hacs.base import HacsRepositories
from custom_components.hacs.enums import HacsGitHubRepo
from custom_components.hacs.utils.data import HacsData

from tests.async_mock import patch
Expand Down Expand Up @@ -82,7 +83,7 @@ def _mocked_load(*_):
assert hacs.repositories.get_by_full_name("shbatm/hacs-isy994")

assert hacs.repositories.get_by_id("172733314")
assert hacs.repositories.get_by_full_name("hacs/integration")
assert hacs.repositories.get_by_full_name(HacsGitHubRepo.INTEGRATION)

assert hacs.repositories.get_by_id("172733314").data.show_beta is True
assert hacs.repositories.get_by_id("172733314").data.installed is True
Expand Down

0 comments on commit 33d7f0c

Please sign in to comment.