Skip to content

Commit

Permalink
Merge pull request #30 from home-assistant/dev
Browse files Browse the repository at this point in the history
Release 0.20
  • Loading branch information
pvizeli authored May 2, 2017
2 parents 0a1e6b3 + 046ce02 commit 79cc23e
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 85 deletions.
12 changes: 7 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ The addons from `addons` are only installed one.
{
"name": "xy bla",
"slug": "xy",
"version": "INSTALL_VERSION",
"last_version": "VERSION_FOR_UPDATE",
"repository": "12345678|null",
"version": "LAST_VERSION",
"installed": "INSTALL_VERSION",
"detached": "bool",
"description": "description"
}
Expand All @@ -59,7 +60,7 @@ Get all available addons
{
"name": "xy bla",
"slug": "xy",
"repository": "12345678|null",
"repository": "core|local|REP_ID",
"version": "LAST_VERSION",
"installed": "none|INSTALL_VERSION",
"detached": "bool",
Expand All @@ -70,8 +71,9 @@ Get all available addons
{
"slug": "12345678",
"name": "Repitory Name",
"url": "WEBSITE",
"maintainer": "BLA BLU <fla@dld.ch>"
"source": "URL_OF_REPOSITORY",
"url": "null|WEBSITE",
"maintainer": "null|BLA BLU <fla@dld.ch>"
}
]
}
Expand Down
69 changes: 11 additions & 58 deletions hassio/addons/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
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_INSTALLED, ATTR_SCHEMA, ATTR_IMAGE, ATTR_DETACHED,
MAP_CONFIG, MAP_SSL, MAP_ADDONS, MAP_BACKUP, ATTR_REPOSITORY, ATTR_URL,
ATTR_MAINTAINER, ATTR_LAST_VERSION)
DOCKER_REPO, ATTR_SCHEMA, ATTR_IMAGE, MAP_CONFIG, MAP_SSL, MAP_ADDONS,
MAP_BACKUP, ATTR_REPOSITORY)
from ..config import Config
from ..tools import read_json_file, write_json_file

Expand Down Expand Up @@ -142,48 +141,12 @@ def list_installed(self):
return set(self._system_data.keys())

@property
def list_all_api(self):
"""Return a list of available addons for api."""
data = []
all_addons = {**self._system_data, **self._addons_cache}
detached = self.list_detached

for addon, values in all_addons.items():
i_version = self._user_data.get(addon, {}).get(ATTR_VERSION)

data.append({
ATTR_NAME: values[ATTR_NAME],
ATTR_SLUG: addon,
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
ATTR_VERSION: values[ATTR_VERSION],
ATTR_INSTALLED: i_version,
ATTR_DETACHED: addon in detached,
ATTR_REPOSITORY: values[ATTR_REPOSITORY],
})

return data

@property
def list_installed_api(self):
"""Return a list of available addons for api."""
data = []
all_addons = {**self._system_data, **self._addons_cache}
detached = self.list_detached

for addon, values in all_addons.items():
i_version = self._user_data.get(addon, {}).get(ATTR_VERSION)

data.append({
ATTR_NAME: values[ATTR_NAME],
ATTR_SLUG: addon,
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
ATTR_VERSION: values[ATTR_VERSION],
ATTR_LAST_VERSION: values[ATTR_VERSION],
ATTR_INSTALLED: i_version,
ATTR_DETACHED: addon in detached
})

return data
def list_all(self):
"""Return a list of all addons."""
return {
**self._system_data,
**self._addons_cache
}

def list_startup(self, start_type):
"""Get list of installed addon with need start by type."""
Expand Down Expand Up @@ -212,19 +175,9 @@ def list_detached(self):
return addon_list

@property
def list_repositories_api(self):
def list_repositories(self):
"""Return list of addon repositories."""
repositories = []

for slug, data in self._repositories_data.items():
repositories.append({
ATTR_SLUG: slug,
ATTR_NAME: data[ATTR_NAME],
ATTR_URL: data.get(ATTR_URL),
ATTR_MAINTAINER: data.get(ATTR_MAINTAINER),
})

return repositories
return list(self._repositories_data.values())

def exists_addon(self, addon):
"""Return True if a addon exists."""
Expand All @@ -236,7 +189,7 @@ def is_installed(self, addon):

def version_installed(self, addon):
"""Return installed version."""
return self._user_data[addon][ATTR_VERSION]
return self._user_data.get(addon, {}).get(ATTR_VERSION)

def set_addon_install(self, addon, version):
"""Set addon as installed."""
Expand Down
5 changes: 5 additions & 0 deletions hassio/addons/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ def extract_hash_from_path(path):
if not RE_SHA1.match(repo_dir):
return get_hash_from_repository(repo_dir)
return repo_dir


def create_hash_index_list(name_list):
"""Create a dict with hash from repositories list."""
return {get_hash_from_repository(repo): repo for repo in name_list}
8 changes: 5 additions & 3 deletions hassio/api/host.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Init file for HassIO host rest api."""
import asyncio
import logging

import voluptuous as vol
Expand Down Expand Up @@ -30,7 +31,7 @@ async def info(self, request):
return {
ATTR_TYPE: self.host_control.type,
ATTR_VERSION: self.host_control.version,
ATTR_LAST_VERSION: self.host_control.last,
ATTR_LAST_VERSION: self.host_control.last_version,
ATTR_FEATURES: self.host_control.features,
ATTR_HOSTNAME: self.host_control.hostname,
ATTR_OS: self.host_control.os_info,
Expand All @@ -50,9 +51,10 @@ def shutdown(self, request):
async def update(self, request):
"""Update host OS."""
body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION)
version = body.get(ATTR_VERSION, self.host_control.last_version)

if version == self.host_control.version:
raise RuntimeError("Version is already in use")

return await self.host_control.update(version=version)
return await asyncio.shield(
self.host_control.update(version=version), loop=self.loop)
50 changes: 46 additions & 4 deletions hassio/api/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import voluptuous as vol

from .util import api_process, api_process_raw, api_validate
from ..addons.util import create_hash_index_list
from ..const import (
ATTR_ADDONS, ATTR_VERSION, ATTR_LAST_VERSION, ATTR_BETA_CHANNEL,
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES)
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES,
ATTR_REPOSITORY, ATTR_DESCRIPTON, ATTR_NAME, ATTR_SLUG, ATTR_INSTALLED,
ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -33,6 +36,42 @@ def __init__(self, config, loop, supervisor, addons, host_control):
self.addons = addons
self.host_control = host_control

def _addons_list(self, only_installed):
"""Return a list of addons."""
data = []
detached = self.addons.list_detached

for addon, values in self.addons.list_all.items():
i_version = self.addons.version_installed(addon)

data.append({
ATTR_NAME: values[ATTR_NAME],
ATTR_SLUG: addon,
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
ATTR_VERSION: values[ATTR_VERSION],
ATTR_INSTALLED: i_version,
ATTR_DETACHED: addon in detached,
ATTR_REPOSITORY: values[ATTR_REPOSITORY],
})

return data

def _repositories_list(self):
"""Return a list of addons repositories."""
data = []
list_id = create_hash_index_list(self.config.addons_repositories)

for repository in self.addons.list_repositories:
data.append({
ATTR_SLUG: repository[ATTR_SLUG],
ATTR_NAME: repository[ATTR_NAME],
ATTR_SOURCE: list_id.get(repository[ATTR_SLUG]),
ATTR_URL: repository.get(ATTR_URL),
ATTR_MAINTAINER: repository.get(ATTR_MAINTAINER),
})

return data

@api_process
async def ping(self, request):
"""Return ok for signal that the api is ready."""
Expand All @@ -45,16 +84,16 @@ async def info(self, request):
ATTR_VERSION: HASSIO_VERSION,
ATTR_LAST_VERSION: self.config.last_hassio,
ATTR_BETA_CHANNEL: self.config.upstream_beta,
ATTR_ADDONS: self.addons.list_installed_api,
ATTR_ADDONS: self._addons_list(only_installed=True),
ATTR_ADDONS_REPOSITORIES: self.config.addons_repositories,
}

@api_process
async def available_addons(self, request):
"""Return information for all available addons."""
return {
ATTR_ADDONS: self.addons.list_all_api,
ATTR_REPOSITORIES: self.addons.list_repositories_api,
ATTR_ADDONS: self._addons_list(only_installed=False),
ATTR_REPOSITORIES: self._repositories_list(),
}

@api_process
Expand All @@ -80,6 +119,9 @@ async def options(self, request):
for url in set(old - new):
self.addons.drop_git_repository(url)

# read repository
self.addons.read_data_from_repositories()

return True

@api_process
Expand Down
4 changes: 2 additions & 2 deletions hassio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .const import FILE_HASSIO_CONFIG, HASSIO_SHARE
from .tools import (
fetch_current_versions, write_json_file, read_json_file)
fetch_last_versions, write_json_file, read_json_file)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, websession):

async def fetch_update_infos(self):
"""Read current versions from web."""
last = await fetch_current_versions(
last = await fetch_last_versions(
self.websession, beta=self.upstream_beta)

if last:
Expand Down
3 changes: 2 additions & 1 deletion hassio/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Const file for HassIO."""
from pathlib import Path

HASSIO_VERSION = '0.19'
HASSIO_VERSION = '0.20'

URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/'
'hassio/master/version.json')
Expand Down Expand Up @@ -36,6 +36,7 @@
ATTR_HOSTNAME = 'hostname'
ATTR_OS = 'os'
ATTR_TYPE = 'type'
ATTR_SOURCE = 'source'
ATTR_FEATURES = 'features'
ATTR_ADDONS = 'addons'
ATTR_VERSION = 'version'
Expand Down
9 changes: 4 additions & 5 deletions hassio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ async def setup(self):

# hostcontrol
await self.host_control.load()
_LOGGER.info(
"Connected to HostControl. Type: %s Version: %s Hostname: %s "
"Features: %s", self.host_control.type,
self.host_control.version, self.host_control.hostname,
self.host_control.features)

# schedule update info tasks
self.scheduler.register_task(
self.host_control.load, RUN_UPDATE_INFO_TASKS)

# rest api views
self.api.register_host(self.host_control)
Expand Down
11 changes: 6 additions & 5 deletions hassio/host_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, loop):
self.loop = loop
self.active = False
self.version = UNKNOWN
self.last = UNKNOWN
self.last_version = UNKNOWN
self.type = UNKNOWN
self.features = []
self.hostname = UNKNOWN
Expand Down Expand Up @@ -57,8 +57,8 @@ async def _send_command(self, command):
writer.write("{}\n".format(command).encode())
data = await reader.readline()

response = data.decode()
_LOGGER.debug("Receive from HostControl: %s.", response)
response = data.decode().rstrip()
_LOGGER.info("Receive from HostControl: %s.", response)

if response == "OK":
return True
Expand All @@ -70,7 +70,8 @@ async def _send_command(self, command):
try:
return json.loads(response)
except json.JSONDecodeError:
_LOGGER.warning("Json parse error from HostControl.")
_LOGGER.warning("Json parse error from HostControl '%s'.",
response)

except asyncio.TimeoutError:
_LOGGER.error("Timeout from HostControl!")
Expand All @@ -88,7 +89,7 @@ async def load(self):
return

self.version = info.get(ATTR_VERSION, UNKNOWN)
self.last = info.get(ATTR_LAST_VERSION, UNKNOWN)
self.last_version = info.get(ATTR_LAST_VERSION, UNKNOWN)
self.type = info.get(ATTR_TYPE, UNKNOWN)
self.features = info.get(ATTR_FEATURES, [])
self.hostname = info.get(ATTR_HOSTNAME, UNKNOWN)
Expand Down
2 changes: 1 addition & 1 deletion hassio/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_IMAGE_ARCH = re.compile(r".*/([a-z0-9]*)-hassio-supervisor")


async def fetch_current_versions(websession, beta=False):
async def fetch_last_versions(websession, beta=False):
"""Fetch current versions from github.
Is a coroutine.
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"hassio": "0.19",
"hassio": "0.20",
"homeassistant": "0.43.2",
"resinos": "0.6",
"resinhup": "0.1",
Expand Down

0 comments on commit 79cc23e

Please sign in to comment.