Skip to content

Commit

Permalink
Merge next into master for 0.9.0 (#109)
Browse files Browse the repository at this point in the history
* Add: Tavos Water Outage and Atrea ventilation integrations (#108)

* Format

* Adding Goodwe Solar power stats to default repositories (#111)

Hi, One of the users of a component I put on Github [asked me](TimSoethout/goodwe-sems-home-assistant#6) to add this component to HACS. 
I hope this change is correct.

* Move "timsoethout/goodwe-sems-home-assistant",

* pin versions

* Limit logging

* Fix broken iOS settings

* Table text color

* Adds more exceptions

* Adds dev mode

* Parse package.json for author

* Pretty names for plugins

* Version bump
  • Loading branch information
ludeeus committed Jun 19, 2019
1 parent 364906e commit 892551f
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 28 deletions.
12 changes: 6 additions & 6 deletions custom_components/hacs/aiogithub.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, token, loop, session):
self._ratelimit_remaining = None
self.headers["Authorization"] = "token {}".format(token)

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def get_repo(self, repo: str):
"""Retrun AIOGithubRepository object."""
if self._ratelimit_remaining == "0":
Expand All @@ -62,7 +62,7 @@ async def get_repo(self, repo: str):

return AIOGithubRepository(response, self.token, self.loop, self.session)

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def get_org_repos(self, org: str, page=1):
"""Retrun a list of AIOGithubRepository objects."""
if self._ratelimit_remaining == "0":
Expand Down Expand Up @@ -95,7 +95,7 @@ async def get_org_repos(self, org: str, page=1):

return repositories

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def render_markdown(self, content: str):
"""Retrun AIOGithubRepository object."""
if self._ratelimit_remaining == "0":
Expand Down Expand Up @@ -167,7 +167,7 @@ def default_branch(self):
def last_commit(self):
return self._last_commit

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def get_contents(self, path, ref=None):
"""Retrun a list of repository content objects."""
if self._ratelimit_remaining == "0":
Expand Down Expand Up @@ -204,7 +204,7 @@ async def get_contents(self, path, ref=None):

return contents

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def get_releases(self, latest=False):
"""Retrun a list of repository release objects."""
if self._ratelimit_remaining == "0":
Expand Down Expand Up @@ -235,7 +235,7 @@ async def get_releases(self, latest=False):

return contents

@backoff.on_exception(backoff.expo, ClientError, max_tries=3)
@backoff.on_exception(backoff.expo, (ClientError, TimeoutError), max_tries=3)
async def set_last_commit(self):
"""Retrun a list of repository release objects."""
if self._ratelimit_remaining == "0":
Expand Down
10 changes: 8 additions & 2 deletions custom_components/hacs/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Constants for HACS"""
VERSION = "0.8.1"
VERSION = "0.9.0"
NAME_LONG = "HACS (Home Assistant Community Store)"
NAME_SHORT = "HACS"
STORAGE_VERSION = "1"
Expand Down Expand Up @@ -73,7 +73,13 @@
################################

DEFAULT_REPOSITORIES = {
"integration": ["StyraHem/ShellyForHASS", "isabellaalstrom/sensor.krisinformation"],
"integration": [
"StyraHem/ShellyForHASS",
"isabellaalstrom/sensor.krisinformation",
"JurajNyiri/HomeAssistant-Tavos",
"JurajNyiri/HomeAssistant-Atrea",
"timsoethout/goodwe-sems-home-assistant",
],
"plugin": [
"maykar/compact-custom-header",
"maykar/lovelace-swipe-navigation",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/frontend/elements/hacs.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
width: 95%;
margin-left: 2.5%;
margin-right: 2.5%;
display: flow-root;
display: inline-block;
}

.hacs-content {
Expand Down
4 changes: 3 additions & 1 deletion custom_components/hacs/frontend/views/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def get(self, request): # pylint: disable=unused-argument
<div class="hacs-card overview">
<meta topics="{}">
<meta repository_authors="{}">
<meta name="{}">
<span class="hacs-card-title">{} {}</span>
<span class="hacs-card-content">
<p>{}</p>
Expand All @@ -71,8 +72,9 @@ async def get(self, request): # pylint: disable=unused-argument
repository.repository_id,
repository.topics,
repository.authors,
card_icon,
repository.name,
card_icon,
repository.name.replace('-', ' ').title(),
repository.description,
)

Expand Down
22 changes: 12 additions & 10 deletions custom_components/hacs/frontend/views/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ async def get(self, request, repository_id):
info = info.replace("<h2>", "<h5>").replace("</h2>", "</h5>")
info = info.replace("<h1>", "<h4>").replace("</h1>", "</h4>")
info = info.replace("<code>", "<code class='codeinfo'>")
info = info.replace("<table>", "<table class='white-text'>")
info = info.replace(
'<a href="http', '<a target="_blank" href="http'
)
Expand All @@ -101,14 +100,17 @@ async def get(self, request, repository_id):
info = ""

if repository.authors:
authors = "<p>Author(s): "
for author in repository.authors:
if "@" in author:
author = author.split("@")[-1]
authors += "<a rel='noreferrer' href='https://github.com/{author}' target='_blank' style='color: var(--primary-color) !important; margin: 2'> @{author}</a>".format(
author=author
)
authors += "</p>"
if repository.repository_type == "integration":
authors = "<p>Author(s): "
for author in repository.authors:
if "@" in author:
author = author.split("@")[-1]
authors += "<a rel='noreferrer' href='https://github.com/{author}' target='_blank' style='color: var(--primary-color) !important; margin: 2'> @{author}</a>".format(
author=author
)
authors += "</p>"
else:
authors = "<p>Author: {}</p>".format(repository.authors)
else:
authors = ""

Expand Down Expand Up @@ -285,7 +287,7 @@ async def get(self, request, repository_id):
""".format(
custom_message,
pending_restart,
repository.name,
repository.name.replace('-', ' ').title(),
self.url_path["api"],
repository.repository_id,
hide_option,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/hacs/frontend/views/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async def get(self, request): # pylint: disable=unused-argument
<div class="hacs-card overview">
<meta topics="{}">
<meta repository_authors="{}">
<meta name="{}">
<span class="hacs-card-title">{} {}</span>
<span class="hacs-card-content">
<p>{}</p>
Expand All @@ -72,8 +73,9 @@ async def get(self, request): # pylint: disable=unused-argument
repository.repository_id,
repository.topics,
repository.authors,
card_icon,
repository.name,
card_icon,
repository.name.replace('-', ' ').title(),
repository.description,
)

Expand Down
18 changes: 12 additions & 6 deletions custom_components/hacs/hacsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HacsBase:
"""The base class of HACS, nested thoughout the project."""

const = None
dev = False
migration = None
storage = None
hacs = None
Expand Down Expand Up @@ -113,7 +114,8 @@ async def register_new_repository(self, element_type, repo, repositoryobject=Non
await repository.set_repository()
await repository.setup_repository()
except (HacsRequirement, HacsBaseException, AIOGitHubException) as exception:
_LOGGER.error("%s - %s", repository.repository_name, exception)
if not self.data["task_running"]:
_LOGGER.error("%s - %s", repository.repository_name, exception)
setup_result = False

if setup_result:
Expand All @@ -122,7 +124,8 @@ async def register_new_repository(self, element_type, repo, repositoryobject=Non
else:
if repo not in self.blacklist:
self.blacklist.append(repo)
_LOGGER.error("%s - Could not register.", repo)
if not self.data["task_running"]:
_LOGGER.error("%s - Could not register.", repo)
return repository, setup_result

async def update_repositories(self, now=None):
Expand Down Expand Up @@ -180,10 +183,13 @@ async def get_repositories(self):
repositories = {}

# Get org repositories
repositories["integration"] = await self.aiogithub.get_org_repos(
"custom-components"
)
repositories["plugin"] = await self.aiogithub.get_org_repos("custom-cards")
if not self.dev:
repositories["integration"] = await self.aiogithub.get_org_repos(
"custom-components"
)
repositories["plugin"] = await self.aiogithub.get_org_repos("custom-cards")
else:
return [], []

# Additional repositories (Not implemented)
for repository_type in DEFAULT_REPOSITORIES:
Expand Down
18 changes: 18 additions & 0 deletions custom_components/hacs/hacsrepositorybaseplugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Blueprint for HacsRepositoryPlugin."""
# pylint: disable=too-many-instance-attributes,invalid-name,broad-except
import logging
import json

from .aiogithub import AIOGitHubException
from .blueprints import HacsRepositoryBase
Expand Down Expand Up @@ -58,8 +59,15 @@ async def update(self):
except AIOGitHubException:
# This can fail, no big deal.
pass

await self.set_repository_content()

try:
await self.get_package_content()
except AIOGitHubException:
# This can fail, no big deal.
pass

async def set_repository_content(self):
"""Set repository content attributes."""
if self.content_path is None or self.content_path == "":
Expand Down Expand Up @@ -126,3 +134,13 @@ async def set_repository_content(self):

if not self.content_files or not self.content_objects:
raise HacsRequirement("No acceptable js files found")

async def get_package_content(self):
"""Get package content."""
package = None

package = await self.repository.get_contents("package.json")
package = json.loads(package.content)

if package:
self.authors = package["author"]
2 changes: 1 addition & 1 deletion custom_components/hacs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"documentation": "https://custom-components.github.io/hacs",
"dependencies": [],
"codeowners": ["@ludeeus"],
"requirements": ["aiofiles", "backoff"]
"requirements": ["aiofiles==0.4.0", "backoff==1.8.0"]
}
2 changes: 2 additions & 0 deletions custom_components/hacs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aiofiles==0.4.0
backoff==1.8.0

0 comments on commit 892551f

Please sign in to comment.