Add support for 0.44.1 (#33)

* Add support for 0.44.1

* fix lint

* fix lint

* fix lint
This commit is contained in:
Pascal Vizeli 2017-05-08 00:19:57 +02:00 committed by GitHub
parent 9998f9720f
commit 5896fde441
4 changed files with 47 additions and 2 deletions

View File

@ -0,0 +1,12 @@
{
"local": {
"name": "Local Add-Ons",
"url": "https://home-assistant.io/hassio",
"maintainer": "By our self"
},
"core": {
"name": "Built-in Add-Ons",
"url": "https://home-assistant.io/addons",
"maintainer": "Home Assistant authors"
}
}

View File

@ -1,6 +1,7 @@
"""Init file for HassIO addons."""
import copy
import logging
import json
from pathlib import Path, PurePath
import voluptuous as vol
@ -13,7 +14,7 @@ from ..const import (
FILE_HASSIO_ADDONS, ATTR_NAME, ATTR_VERSION, ATTR_SLUG, ATTR_DESCRIPTON,
ATTR_STARTUP, ATTR_BOOT, ATTR_MAP, ATTR_OPTIONS, ATTR_PORTS, BOOT_AUTO,
DOCKER_REPO, ATTR_SCHEMA, ATTR_IMAGE, MAP_CONFIG, MAP_SSL, MAP_ADDONS,
MAP_BACKUP, ATTR_REPOSITORY)
MAP_BACKUP, ATTR_REPOSITORY, ATTR_URL)
from ..config import Config
from ..tools import read_json_file, write_json_file
@ -60,6 +61,9 @@ class AddonsData(Config):
self._read_addons_folder(
self.config.path_addons_local, REPOSITORY_LOCAL)
# add built-in repositories information
self._set_builtin_repositories()
# read custom git repositories
for repository_element in self.config.path_addons_git.iterdir():
if repository_element.is_dir():
@ -114,6 +118,29 @@ class AddonsData(Config):
_LOGGER.warning("Can't read %s -> %s", addon,
humanize_error(addon_config, ex))
def _set_builtin_repositories(self):
"""Add local built-in repository into dataset."""
try:
builtin_file = Path(__file__).parent.joinpath('built-in.json')
builtin_data = read_json_file(builtin_file)
except (OSError, json.JSONDecodeError):
_LOGGER.warning("Can't read built-in.json!")
return
# if core addons are available
for data in self._addons_cache.values():
if data[ATTR_REPOSITORY] == REPOSITORY_CORE:
self._repositories_data[REPOSITORY_CORE] = \
builtin_data[REPOSITORY_CORE]
break
# if local addons are available
for data in self._addons_cache.values():
if data[ATTR_REPOSITORY] == REPOSITORY_LOCAL:
self._repositories_data[REPOSITORY_LOCAL] = \
builtin_data[REPOSITORY_LOCAL]
break
def merge_update_config(self):
"""Update local config if they have update.
@ -259,6 +286,10 @@ class AddonsData(Config):
"""Return ports of addon."""
return self._system_data[addon].get(ATTR_PORTS)
def get_url(self, addon):
"""Return url of addon."""
return self._system_data[addon].get(ATTR_URL)
def get_image(self, addon):
"""Return image name of addon."""
addon_data = self._system_data.get(

View File

@ -30,6 +30,7 @@ SCHEMA_ADDON_CONFIG = vol.Schema({
vol.Optional(ATTR_MAP, default=[]): [
vol.In([MAP_CONFIG, MAP_SSL, MAP_ADDONS, MAP_BACKUP])
],
vol.Optional(ATTR_URL): vol.Url(),
vol.Required(ATTR_OPTIONS): dict,
vol.Required(ATTR_SCHEMA): {
vol.Coerce(str): vol.Any(ADDON_ELEMENT, [

View File

@ -8,7 +8,7 @@ from voluptuous.humanize import humanize_error
from .util import api_process, api_process_raw, api_validate
from ..const import (
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_STATE, ATTR_BOOT, ATTR_OPTIONS,
STATE_STOPPED, STATE_STARTED, BOOT_AUTO, BOOT_MANUAL)
ATTR_URL, STATE_STOPPED, STATE_STARTED, BOOT_AUTO, BOOT_MANUAL)
_LOGGER = logging.getLogger(__name__)
@ -53,6 +53,7 @@ class APIAddons(object):
ATTR_STATE: await self.addons.state(addon),
ATTR_BOOT: self.addons.get_boot(addon),
ATTR_OPTIONS: self.addons.get_options(addon),
ATTR_URL: self.addons.get_url(addon),
}
@api_process