Skip to content

Commit

Permalink
chore: 0.118.5
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Dec 5, 2020
1 parent 296c3ab commit c934a85
Show file tree
Hide file tree
Showing 74 changed files with 6,878 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/homeassistant-installed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
- name: Create secrets.yaml
run: mv travis_secrets.yaml secrets.yaml
- name: Home Assistant Check Installed
uses: "docker://homeassistant/home-assistant:0.118.4"
uses: "docker://homeassistant/home-assistant:0.118.5"
with:
args: python -m homeassistant --config . --script check_config --info all
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ version: '2.1'
services:
homeassistant:
container_name: homeassistant
image: homeassistant/home-assistant:0.118.4
image: homeassistant/home-assistant:0.118.5
volumes:
- /home/admin/homeassistant:/config
- /etc/localtime:/etc/localtime:ro
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/api/hacs_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
async def hacs_repository(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
logger = getLogger("api.repository")
logger = getLogger()
data = {}
repository = None

Expand Down
9 changes: 5 additions & 4 deletions custom_components/hacs/api/hacs_repository_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from custom_components.hacs.share import get_hacs

_LOGGER = getLogger()


@websocket_api.async_response
@websocket_api.websocket_command(
Expand All @@ -27,7 +29,6 @@
async def hacs_repository_data(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
logger = getLogger("api.repository_data")
repo_id = msg.get("repository")
action = msg.get("action")
data = msg.get("data")
Expand Down Expand Up @@ -77,7 +78,7 @@ async def hacs_repository_data(hass, connection, msg):
hass.bus.async_fire("hacs/repository", {})
return

logger.debug(f"Running {action} for {repository.data.full_name}")
_LOGGER.debug("Running %s for %s", action, repository.data.full_name)
try:
if action == "set_state":
repository.state = data
Expand All @@ -102,7 +103,7 @@ async def hacs_repository_data(hass, connection, msg):

else:
repository.state = None
logger.error(f"WS action '{action}' is not valid")
_LOGGER.error("WS action '%s' is not valid", action)

message = None
except AIOGitHubAPIException as exception:
Expand All @@ -113,7 +114,7 @@ async def hacs_repository_data(hass, connection, msg):
message = exception

if message is not None:
logger.error(message)
_LOGGER.error(message)
hass.bus.async_fire("hacs/error", {"message": str(message)})

await hacs.data.async_write()
Expand Down
12 changes: 8 additions & 4 deletions custom_components/hacs/api/hacs_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from custom_components.hacs.helpers.functions.logger import getLogger
from custom_components.hacs.share import get_hacs

_LOGGER = getLogger()


@websocket_api.async_response
@websocket_api.websocket_command(
Expand All @@ -18,10 +20,9 @@
async def hacs_settings(hass, connection, msg):
"""Handle get media player cover command."""
hacs = get_hacs()
logger = getLogger("api.settings")

action = msg["action"]
logger.debug(f"WS action '{action}'")
_LOGGER.debug("WS action '%s'", action)

if action == "set_fe_grid":
hacs.configuration.frontend_mode = "Grid"
Expand All @@ -41,10 +42,13 @@ async def hacs_settings(hass, connection, msg):
elif action == "clear_new":
for repo in hacs.repositories:
if repo.data.new and repo.data.category in msg.get("categories", []):
logger.debug(f"Clearing new flag from '{repo.data.full_name}'")
_LOGGER.debug(
"Clearing new flag from '%s'",
repo.data.full_name,
)
repo.data.new = False
else:
logger.error(f"WS action '{action}' is not valid")
_LOGGER.error("WS action '%s' is not valid", action)
hass.bus.async_fire("hacs/config", {})
await hacs.data.async_write()
connection.send_message(websocket_api.result_message(msg["id"], {}))
108 changes: 108 additions & 0 deletions custom_components/hacs/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""Base HACS class."""
import logging
from typing import List, Optional
import attr

from aiogithubapi.github import AIOGitHubAPI
from aiogithubapi.objects.repository import AIOGitHubAPIRepository
from homeassistant.core import HomeAssistant

from .enums import HacsStage
from .helpers.functions.logger import getLogger
from .models.core import HacsCore
from .models.frontend import HacsFrontend
from .models.system import HacsSystem


class HacsCommon:
"""Common for HACS."""

categories: List = []
default: List = []
installed: List = []
skip: List = []


class HacsStatus:
"""HacsStatus."""

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


@attr.s
class HacsBaseAttributes:
"""Base HACS class."""

_default: Optional[AIOGitHubAPIRepository]
_github: Optional[AIOGitHubAPI]
_hass: Optional[HomeAssistant]
_repository: Optional[AIOGitHubAPIRepository]
_stage: HacsStage = HacsStage.SETUP
_common: Optional[HacsCommon]

core: HacsCore = attr.ib(HacsCore)
common: HacsCommon = attr.ib(HacsCommon)
status: HacsStatus = attr.ib(HacsStatus)
frontend: HacsFrontend = attr.ib(HacsFrontend)
log: logging.Logger = getLogger()
system: HacsSystem = attr.ib(HacsSystem)
repositories: List = []


@attr.s
class HacsBase(HacsBaseAttributes):
"""Base HACS class."""

@property
def stage(self) -> HacsStage:
"""Returns a HacsStage object."""
return self._stage

@stage.setter
def stage(self, value: HacsStage) -> None:
"""Set the value for the stage property."""
self._stage = value

@property
def github(self) -> Optional[AIOGitHubAPI]:
"""Returns a AIOGitHubAPI object."""
return self._github

@github.setter
def github(self, value: AIOGitHubAPI) -> None:
"""Set the value for the github property."""
self._github = value

@property
def repository(self) -> Optional[AIOGitHubAPIRepository]:
"""Returns a AIOGitHubAPIRepository object representing hacs/integration."""
return self._repository

@repository.setter
def repository(self, value: AIOGitHubAPIRepository) -> None:
"""Set the value for the repository property."""
self._repository = value

@property
def default(self) -> Optional[AIOGitHubAPIRepository]:
"""Returns a AIOGitHubAPIRepository object representing hacs/default."""
return self._default

@default.setter
def default(self, value: AIOGitHubAPIRepository) -> None:
"""Set the value for the default property."""
self._default = value

@property
def hass(self) -> Optional[HomeAssistant]:
"""Returns a HomeAssistant object."""
return self._hass

@hass.setter
def hass(self, value: HomeAssistant) -> None:
"""Set the value for the default property."""
self._hass = value
98 changes: 71 additions & 27 deletions custom_components/hacs/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"""Adds config flow for HACS."""
import voluptuous as vol
from aiogithubapi import AIOGitHubAPIAuthenticationException, AIOGitHubAPIException
from aiogithubapi import (
AIOGitHubAPIAuthenticationException,
AIOGitHubAPIException,
GitHubDevice,
)
from aiogithubapi.common.const import OAUTH_USER_LOGIN
from homeassistant import config_entries
from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client

from custom_components.hacs.const import DOMAIN
from custom_components.hacs.helpers.functions.configuration_schema import (
hacs_base_config_schema,
hacs_config_option_schema,
)
from custom_components.hacs.helpers.functions.information import get_repository

# pylint: disable=dangerous-default-value
from custom_components.hacs.helpers.functions.logger import getLogger
from custom_components.hacs.share import get_hacs

_LOGGER = getLogger(__name__)
from .base import HacsBase

_LOGGER = getLogger()


class HacsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
Expand All @@ -28,29 +31,83 @@ class HacsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
def __init__(self):
"""Initialize."""
self._errors = {}
self.device = None

async def async_step_device(self, user_input):
"""Handle device steps"""
## Vaiting for token
try:
activation = await self.device.async_device_activation()
return self.async_create_entry(
title="", data={"token": activation.access_token}
)
except (
AIOGitHubAPIException,
AIOGitHubAPIAuthenticationException,
) as exception:
_LOGGER.error(exception)
self._errors["base"] = "auth"
return await self._show_config_form(user_input)

async def async_step_user(self, user_input={}):
async def async_step_user(self, user_input):
"""Handle a flow initialized by the user."""
self._errors = {}
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
if self.hass.data.get(DOMAIN):
return self.async_abort(reason="single_instance_allowed")

if user_input is not None:
if await self._test_token(user_input["token"]):
return self.async_create_entry(title="", data=user_input)
if user_input:
if [x for x in user_input if not user_input[x]]:
self._errors["base"] = "acc"
return await self._show_config_form(user_input)

self._errors["base"] = "auth"
return await self._show_config_form(user_input)
## Get device key
if not self.device:
return await self._show_device_form()

## Initial form
return await self._show_config_form(user_input)

async def _show_device_form(self):
"""Device flow"""
self.device = GitHubDevice(
"395a8e669c5de9f7c6e8",
session=aiohttp_client.async_get_clientsession(self.hass),
)
device_data = await self.device.async_register_device()

return self.async_show_form(
step_id="device",
errors=self._errors,
description_placeholders={
"url": OAUTH_USER_LOGIN,
"code": device_data.user_code,
},
)

async def _show_config_form(self, user_input):
"""Show the configuration form to edit location data."""
if not user_input:
user_input = {}
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(hacs_base_config_schema(user_input)),
data_schema=vol.Schema(
{
vol.Required(
"acc_logs", default=user_input.get("acc_logs", False)
): bool,
vol.Required(
"acc_addons", default=user_input.get("acc_addons", False)
): bool,
vol.Required(
"acc_untested", default=user_input.get("acc_untested", False)
): bool,
vol.Required(
"acc_disable", default=user_input.get("acc_disable", False)
): bool,
}
),
errors=self._errors,
)

Expand All @@ -59,19 +116,6 @@ async def _show_config_form(self, user_input):
def async_get_options_flow(config_entry):
return HacsOptionsFlowHandler(config_entry)

async def _test_token(self, token):
"""Return true if token is valid."""
try:
session = aiohttp_client.async_get_clientsession(self.hass)
await get_repository(session, token, "hacs/org")
return True
except (
AIOGitHubAPIException,
AIOGitHubAPIAuthenticationException,
) as exception:
_LOGGER.error(exception)
return False


class HacsOptionsFlowHandler(config_entries.OptionsFlow):
"""HACS config flow options handler."""
Expand All @@ -86,7 +130,7 @@ async def async_step_init(self, _user_input=None):

async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
hacs = get_hacs()
hacs: HacsBase = get_hacs()
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

Expand Down
4 changes: 3 additions & 1 deletion custom_components/hacs/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Constants for HACS"""
NAME_LONG = "HACS (Home Assistant Community Store)"
NAME_SHORT = "HACS"
VERSION = "1.6.2"
VERSION = "1.8.0"
DOMAIN = "hacs"
PROJECT_URL = "https://github.com/hacs/integration/"
CUSTOM_UPDATER_LOCATIONS = [
Expand All @@ -14,6 +14,8 @@

ELEMENT_TYPES = ["integration", "plugin"]

PACKAGE_NAME = "custom_components.hacs"

IFRAME = {
"title": "HACS",
"icon": "hacs:hacs",
Expand Down
Loading

0 comments on commit c934a85

Please sign in to comment.