Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kernehed committed Feb 21, 2020
1 parent 9d408d1 commit 39ef64b
Show file tree
Hide file tree
Showing 65 changed files with 253 additions and 68 deletions.
9 changes: 6 additions & 3 deletions automations/tts/welcome_home_guests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ initial_state: 'on'
trigger:
- platform: state
entity_id:
- device_tracker.annasiphone
- device_tracker.ingelas_iphone
- device_tracker.andreass_iphone
- device_tracker.matildas_iphone
- device_tracker.daniels_iphone
from: 'not_home'
to: 'home'
for: '00:02:00'
Expand All @@ -17,10 +18,12 @@ action:
- service: script.speech_engine
data_template:
personarriving_guests: >-
{%- if trigger.entity_id == 'device_tracker.annasiphone' -%}
{%- set person = "Anna" -%}
{%- if trigger.entity_id == 'device_tracker.matildas_iphone' -%}
{%- set person = "Matilda" -%}
{%- elif trigger.entity_id == 'device_tracker.ingelas_iphone' -%}
{%- set person = "Ingela" -%}
{%- elif trigger.entity_id == 'device_tracker.daniels_iphone' -%}
{%- set person = "Daniel" -%}
{%- elif trigger.entity_id == 'device_tracker.andreass_iphone' -%}
{%- set person = "Andreas" -%}
{%- else -%}
Expand Down
6 changes: 6 additions & 0 deletions components/sensors/scrape/other/dagens_citat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
platform: scrape
name: dagens citat
resource: https://www.dagenscitat.nu/rss.xml
select: 'description'
index: 1
scan_interval: 3600
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/anniversaries/__pycache__/const.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/anniversaries/__pycache__/sensor.cpython-37.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion custom_components/anniversaries/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Base component constants
DOMAIN = "anniversaries"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "1.5.0"
VERSION = "1.7.0"
PLATFORM = "sensor"
ISSUE_URL = "https://github.com/pinkywafer/Anniversaries/issues"
ATTRIBUTION = "Data from this is provided by Anniversaries"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/anniversaries/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def async_update(self):
daysRemaining = (nextDate - today).days
years = years + 1
if self._unknown_year:
self._date = nextDate
self._date = datetime(nextDate.year, nextDate.month, nextDate.day)

if daysRemaining == 0:
self._icon = self._icon_today
Expand All @@ -126,4 +126,4 @@ async def async_update(self):
self._state = daysRemaining
self._years_next = years
self._years_current = years - 1
self._weeks_remaining = int(daysRemaining / 7)
self._weeks_remaining = int(daysRemaining / 7)
Binary file modified custom_components/hacs/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/config_flow.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/const.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/constrains.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/http.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/sensor.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/setup.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/__pycache__/store.cpython-37.pyc
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 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 = "0.21.1"
VERSION = "0.21.5"
DOMAIN = "hacs"
PROJECT_URL = "https://github.com/hacs/integration/"
CUSTOM_UPDATER_LOCATIONS = [
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/hacs/hacsbase/__pycache__/const.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/hacsbase/__pycache__/data.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/hacs/handler/__pycache__/download.cpython-37.pyc
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions custom_components/hacs/handler/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ async def async_save_file(location, content):
with gzip.open(location + ".gz", "wb") as f_out:
shutil.copyfileobj(f_in, f_out)

# Remove with 2.0
if "themes" in location and location.endswith(".yaml"):
filename = location.split("/")[-1]
base = location.split("/themes/")[0]
combined = f"{base}/themes/{filename}"
if os.path.exists(combined):
logger.info(f"Removing old theme file {combined}")
os.remove(combined)

except Exception as error: # pylint: disable=broad-except
msg = "Could not write data to {} - {}".format(location, error)
logger.error(msg)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified custom_components/hacs/helpers/__pycache__/install.cpython-37.pyc
Binary file not shown.
Binary file modified custom_components/hacs/helpers/__pycache__/misc.cpython-37.pyc
Binary file not shown.
110 changes: 88 additions & 22 deletions custom_components/hacs/helpers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,89 @@
import zipfile
from custom_components.hacs.hacsbase.exceptions import HacsException
from custom_components.hacs.handler.download import async_download_file, async_save_file
from custom_components.hacs.helpers.filters import filter_content_return_one_of_type


class FileInformation:
def __init__(self, url, path, name):
self.download_url = url
self.path = path
self.name = name


def should_try_releases(repository):
"""Return a boolean indicating whether to download releases or not."""
if repository.ref == repository.information.default_branch:
return False
if repository.information.category not in ["plugin", "theme"]:
return False
if not repository.releases.releases:
return False
return True


def gather_files_to_download(repository):
"""Return a list of file objects to be downloaded."""
files = []
tree = repository.tree
ref = f"{repository.ref}".replace("tags/", "")
releaseobjects = repository.releases.objects
category = repository.information.category
remotelocation = repository.content.path.remote

if should_try_releases(repository):
for release in releaseobjects or []:
if ref == release.tag_name:
for asset in release.assets or []:
files.append(asset)
if files:
return files

if repository.content.single:
for treefile in tree:
if treefile.filename == repository.information.file_name:
files.append(
FileInformation(
treefile.download_url, treefile.full_path, treefile.filename
)
)
return files

if category == "plugin":
for treefile in tree:
if treefile.path in ["", "dist"]:
if not remotelocation:
if treefile.filename != repository.information.file_name:
continue
if remotelocation == "dist" and not treefile.filename.startswith(
"dist"
):
continue
if treefile.is_directory:
continue
files.append(
FileInformation(
treefile.download_url, treefile.full_path, treefile.filename
)
)
if files:
return files

if repository.repository_manifest.content_in_root:
if repository.repository_manifest.filename is None:
if category == "theme":
tree = filter_content_return_one_of_type(
repository.tree, "themes", "yaml", "full_path"
)

for path in tree:
if path.is_directory:
continue
if path.full_path.startswith(repository.content.path.remote):
files.append(
FileInformation(path.download_url, path.full_path, path.filename)
)
return files


async def download_zip(repository, validate):
Expand Down Expand Up @@ -51,33 +134,16 @@ async def download_zip(repository, validate):

async def download_content(repository, validate, local_directory):
"""Download the content of a directory."""
contents = []
contents = gather_files_to_download(repository)
try:
if repository.releases.releases and repository.information.category in [
"plugin",
"theme",
]:
for release in repository.releases.objects:
if repository.status.selected_tag == release.tag_name:
for asset in release.assets:
contents.append(asset)
if not contents:
if repository.content.single:
for repository_object in repository.content.objects:
contents.append(repository_object)
else:
tree = await repository.repository_object.get_tree(repository.ref)
for path in tree:
if path.is_directory:
continue
if repository.content.path.remote in path.full_path:
path.name = path.filename
contents.append(path)

if not contents:
raise HacsException("No content to download")

for content in contents:
if repository.repository_manifest.content_in_root:
if repository.repository_manifest.filename is not None:
if content.name != repository.repository_manifest.filename:
continue
repository.logger.debug(f"Downloading {content.name}")

filecontent = await async_download_file(
Expand Down
44 changes: 44 additions & 0 deletions custom_components/hacs/helpers/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Filter functions."""


def filter_content_return_one_of_type(
content, namestartswith, filterfiltype, attr="name"
):
"""Only match 1 of the filter."""
contents = []
filetypefound = False
for filename in content:
if isinstance(filename, str):
if filename.startswith(namestartswith):
if filename.endswith(f".{filterfiltype}"):
if not filetypefound:
contents.append(filename)
filetypefound = True
continue
else:
contents.append(filename)
else:
if getattr(filename, attr).startswith(namestartswith):
if getattr(filename, attr).endswith(f".{filterfiltype}"):
if not filetypefound:
contents.append(filename)
filetypefound = True
continue
else:
contents.append(filename)
return contents


def find_first_of_filetype(content, filterfiltype, attr="name"):
"""Find the first of the file type."""
filename = ""
for _filename in content:
if isinstance(_filename, str):
if _filename.endswith(f".{filterfiltype}"):
filename = _filename
break
else:
if getattr(_filename, attr).endswith(f".{filterfiltype}"):
filename = getattr(_filename, attr)
break
return filename
8 changes: 7 additions & 1 deletion custom_components/hacs/helpers/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
async def install_repository(repository):
"""Common installation steps of the repository."""
persistent_directory = None
await repository.update_repository()

if not repository.can_install:
raise HacsException(
Expand Down Expand Up @@ -35,7 +36,10 @@ async def install_repository(repository):
backup = Backup(repository.content.path.local)
backup.create()

if repository.repository_manifest.zip_release:
if (
repository.repository_manifest.zip_release
and version != repository.information.default_branch
):
validate = await repository.download_zip(repository.validate)
else:
validate = await repository.download_content(
Expand Down Expand Up @@ -115,4 +119,6 @@ def version_to_install(repository):
return repository.information.default_branch
if repository.status.selected_tag in repository.releases.published_tags:
return repository.status.selected_tag
if repository.information.default_branch is None:
return "master"
return repository.information.default_branch
5 changes: 4 additions & 1 deletion custom_components/hacs/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ async def get(self, request, requested_file): # pylint: disable=unused-argument
)

try:
file = f"{self.system.config_path}/www/community/{requested_file}"
if requested_file.startswith("themes"):
file = f"{self.system.config_path}/{requested_file}"
else:
file = f"{self.system.config_path}/www/community/{requested_file}"

# Serve .gz if it exist
if os.path.exists(file + ".gz"):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"aiofiles==0.4.0",
"aiogithubapi==0.5.0",
"backoff==1.10.0",
"hacs_frontend==20200209160602",
"hacs_frontend==20200212060803",
"integrationhelper==0.2.2",
"semantic_version==2.8.4"
]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 20 additions & 1 deletion custom_components/hacs/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class HacsRepository(Hacs):
def __init__(self):
"""Set up HacsRepository."""

self.data = {}
self.content = RepositoryContent()
self.content.path = RepositoryPath()
self.information = RepositoryInformation()
Expand All @@ -116,6 +117,8 @@ def __init__(self):
self.versions = RepositoryVersions()
self.pending_restart = False
self.logger = None
self.tree = []
self.treefiles = []
self.ref = None

@property
Expand Down Expand Up @@ -259,7 +262,6 @@ async def common_validate(self):
self.logger = Logger(
f"hacs.repository.{self.information.category}.{self.information.full_name}"
)

if self.ref is None:
self.ref = version_to_install(self)

Expand All @@ -269,12 +271,19 @@ async def common_validate(self):
self.repository_object = await self.github.get_repo(
self.information.full_name
)
self.data = self.repository_object.attributes
except Exception as exception: # Gotta Catch 'Em All
if not self.system.status.startup:
self.logger.error(exception)
self.validate.errors.append("Repository does not exist.")
return

if not self.tree:
self.tree = await self.repository_object.get_tree(self.ref)
self.treefiles = []
for treefile in self.tree:
self.treefiles.append(treefile.full_path)

# Step 2: Make sure the repository is not archived.
if self.repository_object.archived:
self.validate.errors.append("Repository is archived.")
Expand Down Expand Up @@ -336,9 +345,19 @@ async def common_update(self):

self.logger.debug("Getting repository information")

# Set ref
if self.ref is None:
self.ref = version_to_install(self)

# Attach repository
self.repository_object = await self.github.get_repo(self.information.full_name)

# Update tree
self.tree = await self.repository_object.get_tree(self.ref)
self.treefiles = []
for treefile in self.tree:
self.treefiles.append(treefile.full_path)

# Update description
if self.repository_object.description:
self.information.description = self.repository_object.description
Expand Down
Loading

0 comments on commit 39ef64b

Please sign in to comment.