Skip to content

Commit

Permalink
Ship it? Ship it!
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed May 21, 2019
1 parent 4071f5d commit c9c1698
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 90 deletions.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Issue
about: Create a new issue

---

<!-- Before you open a new issue, search through the existing issues to see if others have had the same problem.
Issues not containing the minimum requirements will be closed:
- Issues without a description (using the header is not good enough) will be closed.
- Issues without debug logging will be closed.
-->

## Version of HACS
<!-- If you are not using the newest version, download and try that before opening an issue
If you are unsure about the version check the "SETTINGS" tab.
-->


## Describe the bug
A clear and concise description of what the bug is.


## Debug log

<!-- To enable debug logs check this https://www.home-assistant.io/components/logger/
You can get the log by clicking the "OPEN LOG" button under the "SETTINGS" tab.
-->

```text
Add your logs here.
```
23 changes: 23 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repository:
private: false
has_issues: true
has_projects: false
has_wiki: false
has_downloads: false
default_branch: master
allow_squash_merge: true
allow_merge_commit: false
allow_rebase_merge: false
labels:
- name: "Feature Request"
color: "fbca04"
- name: "Bug"
color: "b60205"
- name: "Wont Fix"
color: "ffffff"
- name: "Enhancement"
color: a2eeef
- name: "Documentation"
color: "008672"
- name: "Stale"
color: "930191"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Joakim Sørensen @ludeeus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 7 additions & 10 deletions custom_components/hacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
Custom element manager for community created elements.
For more details about this component, please refer to the documentation at
https://github.com/custom-components/hacs (eventually)
For now:
in configuration.yaml:
hacs:
token: xxxxxxxxxxxxxxxxxx
-------------------------------------
The token is a GitHub Access token, you can create one here:
https://github.com/settings/tokens
You don't have to check any of the boxes.
https://custom-components.github.io/hacs/
"""
import logging
import os.path
Expand Down Expand Up @@ -59,6 +50,9 @@

INTERVAL = timedelta(minutes=500)

# TODO: Requirements are not loaded from manifest, needs investigation.
REQUIREMENTS = ["PyGithub", "markdown"]

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = vol.Schema(
Expand Down Expand Up @@ -144,6 +138,9 @@ async def startup_tasks(self):
self.hass.data[DOMAIN_DATA]["repos"] = returndata["repos"]
self.hass.data[DOMAIN_DATA]["hacs"] = returndata["hacs"]

# Make sure we have the correct version
self.hass.data[DOMAIN_DATA]["hacs"]["local"] = VERSION

# Reset restart_pending flag
self.hass.data[DOMAIN_DATA]["hacs"]["restart_pending"] = False
for element in self.hass.data[DOMAIN_DATA]["elements"]:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Constants for HACS"""
VERSION = None
VERSION = "0.1.0"
NAME_LONG = "HACS (Home Assistant Community Store)"
NAME_SHORT = "HACS"
STORENAME = "hacs"
Expand Down
3 changes: 1 addition & 2 deletions custom_components/hacs/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def __init__(self, element_type, name):
self.isinstalled = False
self.installed_version = None
self.avaiable_version = None
self.example_config = None
self.example_image = None
self.info = None
self.manifest = None
self.remote_dir_location = None
self.authors = []
61 changes: 27 additions & 34 deletions custom_components/hacs/frontend/elements/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def avaiable_version(self):
<p>
<b>Available version:</b> {}
</p>
</br>
""".format(
self.element.avaiable_version
)
Expand Down Expand Up @@ -136,14 +137,12 @@ async def element_note(self):
When installed, this will be located in '{config}/www/community/{element}',
you still need to add it to your lovelace configuration ('ui-lovelace.yaml' or the raw UI config editor).
</i>
</br>
</br></br>
<i>
When you add this to your configuration use this as the URL:
</i>
</br>
<i>
'/community_plugin/{element}/{file_name}.js'
</i>
<pre class="yaml">url: /community_plugin/{element}/{file_name}.js</pre>
</br></br>
<i>
To learn more about how to configure this,
Expand All @@ -157,40 +156,35 @@ async def element_note(self):
else:
return ""

async def example_config(self):
"""Generate example config."""
_LOGGER.debug("Generating example config for %s", self.element.element_id)
async def info(self):
"""Generate info."""
import markdown

if self.element.example_config is None:
return ""
_LOGGER.debug("Generating info for %s", self.element.element_id)

return """
</br>
<p>
Example configuration:
</p>
<pre class="yaml"
{}
</pre>
</br>
""".format(
self.element.example_config
)

async def example_image(self):
"""Generate example image."""
_LOGGER.debug("Generating example image for %s", self.element.element_id)

if self.element.example_image is None:
if self.element.info is None:
return ""

return """
</br></br>
<img class="responsive-img" src="{}">
</br>
""".format(
self.element.example_image
markdown_render = markdown.markdown(
self.element.info,
extensions=["markdown.extensions.tables", "markdown.extensions.codehilite"],
)
markdown_render = markdown_render.replace("<h3>", "<h6>").replace(
"</h3>", "</h6>"
)
markdown_render = markdown_render.replace("<h2>", "<h5>").replace(
"</h2>", "</h5>"
)
markdown_render = markdown_render.replace("<h1>", "<h4>").replace(
"</h1>", "</h4>"
)
markdown_render = markdown_render.replace("<code>", "<pre>").replace(
"</code>", "</pre>"
)
markdown_render = markdown_render.replace(
"<table>", "<table class='responsive-table white-text'>"
)
return "<span>{}</span>".format(markdown_render)

async def installed_version(self):
"""Generate installed version."""
Expand All @@ -200,7 +194,6 @@ async def installed_version(self):
return ""

return """
</br>
<p>
<b>Installed version:</b> {}
</p>
Expand Down
9 changes: 3 additions & 6 deletions custom_components/hacs/frontend/views/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ async def element_view_content(self):
changelog = await self.generate.changelog()
description = await self.generate.description()
element_note = await self.generate.element_note()
example_config = await self.generate.example_config()
example_image = await self.generate.example_image()
info = await self.generate.info()
installed_version = await self.generate.installed_version()
main_action = await self.generate.main_action()
name = self.element.name
Expand All @@ -89,8 +88,7 @@ async def element_view_content(self):
{description}
{installed_version}
{avaiable_version}
{example_image}
{example_config}
{info}
</br>
{authors}
{element_note}
Expand All @@ -110,8 +108,7 @@ async def element_view_content(self):
changelog=changelog,
description=description,
element_note=element_note,
example_config=example_config,
example_image=example_image,
info=info,
installed_version=installed_version,
main_action=main_action,
name=name,
Expand Down
27 changes: 16 additions & 11 deletions custom_components/hacs/handler/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,32 @@ async def async_download_file(hass, url):
"""
Download files, and return the content.
"""
_LOGGER.debug("Donwloading from %s", url)

# There is a bug somewhere... TODO: Find that bug....
if "tags/" in url:
_LOGGER.debug(
"tags/ are in '%s', this is beeing removed, but this IS a bug.", url
)
url = url.replace("tags/", "")

_LOGGER.debug("Donwloading from %s", url)

result = None

with async_timeout.timeout(5, loop=hass.loop):
request = await async_get_clientsession(hass).get(url)
try:
with async_timeout.timeout(5, loop=hass.loop):
request = await async_get_clientsession(hass).get(url)

# Make sure that we got a valid result
if request.status == 200:
result = await request.text()
else:
_LOGGER.debug(
"Got status code %s when trying to download %s", request.status, url
)

except Exception as error: # pylint: disable=broad-except
_LOGGER.debug("Downloading %s failed with %s", url, error)

# Make sure that we got a valid result
if request.status == 200:
result = await request.text()
else:
_LOGGER.debug(
"Got status code %s when trying to download %s", request.status, url
)
return result


Expand Down
30 changes: 11 additions & 19 deletions custom_components/hacs/handler/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,12 @@ async def load_integrations_from_git(hass, repo_name):

################### Load custom info from repo. ###################

# Get example config
# Get info.md
try:
example = repo.get_file_contents("example.yaml", ref).decoded_content.decode()
element.example_config = example
except Exception as error: # pylint: disable=broad-except
_LOGGER.debug(error)

# Get example image
try:
element.example_image = repo.get_file_contents("example.png").download_url
info = repo.get_file_contents("info.md", ref).decoded_content.decode()
element.info = info
except Exception as error: # pylint: disable=broad-except
element.info = ""
_LOGGER.debug(error)

# PrettyDescription
Expand Down Expand Up @@ -188,6 +183,8 @@ async def load_plugins_from_git(hass, repo_name):
# Try to find files
files = []

repo_root = repo.get_dir_contents("", ref)

if element.remote_dir_location is None:
# Try RepoRoot/dist/
try:
Expand All @@ -203,8 +200,7 @@ async def load_plugins_from_git(hass, repo_name):
if element.remote_dir_location is None:
# Try RepoRoot/
try:
test_remote_dir_location = repo.get_dir_contents("", ref)
for file in list(test_remote_dir_location):
for file in list(repo_root):
if file.name.endswith(".js"):
files.append(file)
if files:
Expand All @@ -227,17 +223,13 @@ async def load_plugins_from_git(hass, repo_name):
element.repo = repo_name

################### Load custom info from repo. ###################
# Get example config
try:
example = repo.get_file_contents("example.yaml", ref).decoded_content.decode()
element.example_config = example
except Exception as error: # pylint: disable=broad-except
_LOGGER.debug(error)

# Get example image
# Get info.md
try:
element.example_image = repo.get_file_contents("example.png").download_url
info = repo.get_file_contents("info.md", ref).decoded_content.decode()
element.info = info
except Exception as error: # pylint: disable=broad-except
element.info = ""
_LOGGER.debug(error)

# PrettyDescription
Expand Down
Loading

0 comments on commit c9c1698

Please sign in to comment.