Skip to content

Commit 79cc23e

Browse files
authored
Merge pull request #30 from home-assistant/dev
Release 0.20
2 parents 0a1e6b3 + 046ce02 commit 79cc23e

File tree

11 files changed

+90
-85
lines changed

11 files changed

+90
-85
lines changed

API.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ The addons from `addons` are only installed one.
3737
{
3838
"name": "xy bla",
3939
"slug": "xy",
40-
"version": "INSTALL_VERSION",
41-
"last_version": "VERSION_FOR_UPDATE",
40+
"repository": "12345678|null",
41+
"version": "LAST_VERSION",
42+
"installed": "INSTALL_VERSION",
4243
"detached": "bool",
4344
"description": "description"
4445
}
@@ -59,7 +60,7 @@ Get all available addons
5960
{
6061
"name": "xy bla",
6162
"slug": "xy",
62-
"repository": "12345678|null",
63+
"repository": "core|local|REP_ID",
6364
"version": "LAST_VERSION",
6465
"installed": "none|INSTALL_VERSION",
6566
"detached": "bool",
@@ -70,8 +71,9 @@ Get all available addons
7071
{
7172
"slug": "12345678",
7273
"name": "Repitory Name",
73-
"url": "WEBSITE",
74-
"maintainer": "BLA BLU <fla@dld.ch>"
74+
"source": "URL_OF_REPOSITORY",
75+
"url": "null|WEBSITE",
76+
"maintainer": "null|BLA BLU <fla@dld.ch>"
7577
}
7678
]
7779
}

hassio/addons/data.py

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
from ..const import (
1313
FILE_HASSIO_ADDONS, ATTR_NAME, ATTR_VERSION, ATTR_SLUG, ATTR_DESCRIPTON,
1414
ATTR_STARTUP, ATTR_BOOT, ATTR_MAP, ATTR_OPTIONS, ATTR_PORTS, BOOT_AUTO,
15-
DOCKER_REPO, ATTR_INSTALLED, ATTR_SCHEMA, ATTR_IMAGE, ATTR_DETACHED,
16-
MAP_CONFIG, MAP_SSL, MAP_ADDONS, MAP_BACKUP, ATTR_REPOSITORY, ATTR_URL,
17-
ATTR_MAINTAINER, ATTR_LAST_VERSION)
15+
DOCKER_REPO, ATTR_SCHEMA, ATTR_IMAGE, MAP_CONFIG, MAP_SSL, MAP_ADDONS,
16+
MAP_BACKUP, ATTR_REPOSITORY)
1817
from ..config import Config
1918
from ..tools import read_json_file, write_json_file
2019

@@ -142,48 +141,12 @@ def list_installed(self):
142141
return set(self._system_data.keys())
143142

144143
@property
145-
def list_all_api(self):
146-
"""Return a list of available addons for api."""
147-
data = []
148-
all_addons = {**self._system_data, **self._addons_cache}
149-
detached = self.list_detached
150-
151-
for addon, values in all_addons.items():
152-
i_version = self._user_data.get(addon, {}).get(ATTR_VERSION)
153-
154-
data.append({
155-
ATTR_NAME: values[ATTR_NAME],
156-
ATTR_SLUG: addon,
157-
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
158-
ATTR_VERSION: values[ATTR_VERSION],
159-
ATTR_INSTALLED: i_version,
160-
ATTR_DETACHED: addon in detached,
161-
ATTR_REPOSITORY: values[ATTR_REPOSITORY],
162-
})
163-
164-
return data
165-
166-
@property
167-
def list_installed_api(self):
168-
"""Return a list of available addons for api."""
169-
data = []
170-
all_addons = {**self._system_data, **self._addons_cache}
171-
detached = self.list_detached
172-
173-
for addon, values in all_addons.items():
174-
i_version = self._user_data.get(addon, {}).get(ATTR_VERSION)
175-
176-
data.append({
177-
ATTR_NAME: values[ATTR_NAME],
178-
ATTR_SLUG: addon,
179-
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
180-
ATTR_VERSION: values[ATTR_VERSION],
181-
ATTR_LAST_VERSION: values[ATTR_VERSION],
182-
ATTR_INSTALLED: i_version,
183-
ATTR_DETACHED: addon in detached
184-
})
185-
186-
return data
144+
def list_all(self):
145+
"""Return a list of all addons."""
146+
return {
147+
**self._system_data,
148+
**self._addons_cache
149+
}
187150

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

214177
@property
215-
def list_repositories_api(self):
178+
def list_repositories(self):
216179
"""Return list of addon repositories."""
217-
repositories = []
218-
219-
for slug, data in self._repositories_data.items():
220-
repositories.append({
221-
ATTR_SLUG: slug,
222-
ATTR_NAME: data[ATTR_NAME],
223-
ATTR_URL: data.get(ATTR_URL),
224-
ATTR_MAINTAINER: data.get(ATTR_MAINTAINER),
225-
})
226-
227-
return repositories
180+
return list(self._repositories_data.values())
228181

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

237190
def version_installed(self, addon):
238191
"""Return installed version."""
239-
return self._user_data[addon][ATTR_VERSION]
192+
return self._user_data.get(addon, {}).get(ATTR_VERSION)
240193

241194
def set_addon_install(self, addon, version):
242195
"""Set addon as installed."""

hassio/addons/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ def extract_hash_from_path(path):
1919
if not RE_SHA1.match(repo_dir):
2020
return get_hash_from_repository(repo_dir)
2121
return repo_dir
22+
23+
24+
def create_hash_index_list(name_list):
25+
"""Create a dict with hash from repositories list."""
26+
return {get_hash_from_repository(repo): repo for repo in name_list}

hassio/api/host.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Init file for HassIO host rest api."""
2+
import asyncio
23
import logging
34

45
import voluptuous as vol
@@ -30,7 +31,7 @@ async def info(self, request):
3031
return {
3132
ATTR_TYPE: self.host_control.type,
3233
ATTR_VERSION: self.host_control.version,
33-
ATTR_LAST_VERSION: self.host_control.last,
34+
ATTR_LAST_VERSION: self.host_control.last_version,
3435
ATTR_FEATURES: self.host_control.features,
3536
ATTR_HOSTNAME: self.host_control.hostname,
3637
ATTR_OS: self.host_control.os_info,
@@ -50,9 +51,10 @@ def shutdown(self, request):
5051
async def update(self, request):
5152
"""Update host OS."""
5253
body = await api_validate(SCHEMA_VERSION, request)
53-
version = body.get(ATTR_VERSION)
54+
version = body.get(ATTR_VERSION, self.host_control.last_version)
5455

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

58-
return await self.host_control.update(version=version)
59+
return await asyncio.shield(
60+
self.host_control.update(version=version), loop=self.loop)

hassio/api/supervisor.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import voluptuous as vol
66

77
from .util import api_process, api_process_raw, api_validate
8+
from ..addons.util import create_hash_index_list
89
from ..const import (
910
ATTR_ADDONS, ATTR_VERSION, ATTR_LAST_VERSION, ATTR_BETA_CHANNEL,
10-
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES)
11+
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES,
12+
ATTR_REPOSITORY, ATTR_DESCRIPTON, ATTR_NAME, ATTR_SLUG, ATTR_INSTALLED,
13+
ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL)
1114

1215
_LOGGER = logging.getLogger(__name__)
1316

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

39+
def _addons_list(self, only_installed):
40+
"""Return a list of addons."""
41+
data = []
42+
detached = self.addons.list_detached
43+
44+
for addon, values in self.addons.list_all.items():
45+
i_version = self.addons.version_installed(addon)
46+
47+
data.append({
48+
ATTR_NAME: values[ATTR_NAME],
49+
ATTR_SLUG: addon,
50+
ATTR_DESCRIPTON: values[ATTR_DESCRIPTON],
51+
ATTR_VERSION: values[ATTR_VERSION],
52+
ATTR_INSTALLED: i_version,
53+
ATTR_DETACHED: addon in detached,
54+
ATTR_REPOSITORY: values[ATTR_REPOSITORY],
55+
})
56+
57+
return data
58+
59+
def _repositories_list(self):
60+
"""Return a list of addons repositories."""
61+
data = []
62+
list_id = create_hash_index_list(self.config.addons_repositories)
63+
64+
for repository in self.addons.list_repositories:
65+
data.append({
66+
ATTR_SLUG: repository[ATTR_SLUG],
67+
ATTR_NAME: repository[ATTR_NAME],
68+
ATTR_SOURCE: list_id.get(repository[ATTR_SLUG]),
69+
ATTR_URL: repository.get(ATTR_URL),
70+
ATTR_MAINTAINER: repository.get(ATTR_MAINTAINER),
71+
})
72+
73+
return data
74+
3675
@api_process
3776
async def ping(self, request):
3877
"""Return ok for signal that the api is ready."""
@@ -45,16 +84,16 @@ async def info(self, request):
4584
ATTR_VERSION: HASSIO_VERSION,
4685
ATTR_LAST_VERSION: self.config.last_hassio,
4786
ATTR_BETA_CHANNEL: self.config.upstream_beta,
48-
ATTR_ADDONS: self.addons.list_installed_api,
87+
ATTR_ADDONS: self._addons_list(only_installed=True),
4988
ATTR_ADDONS_REPOSITORIES: self.config.addons_repositories,
5089
}
5190

5291
@api_process
5392
async def available_addons(self, request):
5493
"""Return information for all available addons."""
5594
return {
56-
ATTR_ADDONS: self.addons.list_all_api,
57-
ATTR_REPOSITORIES: self.addons.list_repositories_api,
95+
ATTR_ADDONS: self._addons_list(only_installed=False),
96+
ATTR_REPOSITORIES: self._repositories_list(),
5897
}
5998

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

122+
# read repository
123+
self.addons.read_data_from_repositories()
124+
83125
return True
84126

85127
@api_process

hassio/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .const import FILE_HASSIO_CONFIG, HASSIO_SHARE
1111
from .tools import (
12-
fetch_current_versions, write_json_file, read_json_file)
12+
fetch_last_versions, write_json_file, read_json_file)
1313

1414
_LOGGER = logging.getLogger(__name__)
1515

@@ -87,7 +87,7 @@ def __init__(self, websession):
8787

8888
async def fetch_update_infos(self):
8989
"""Read current versions from web."""
90-
last = await fetch_current_versions(
90+
last = await fetch_last_versions(
9191
self.websession, beta=self.upstream_beta)
9292

9393
if last:

hassio/const.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Const file for HassIO."""
22
from pathlib import Path
33

4-
HASSIO_VERSION = '0.19'
4+
HASSIO_VERSION = '0.20'
55

66
URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/'
77
'hassio/master/version.json')
@@ -36,6 +36,7 @@
3636
ATTR_HOSTNAME = 'hostname'
3737
ATTR_OS = 'os'
3838
ATTR_TYPE = 'type'
39+
ATTR_SOURCE = 'source'
3940
ATTR_FEATURES = 'features'
4041
ATTR_ADDONS = 'addons'
4142
ATTR_VERSION = 'version'

hassio/core.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ async def setup(self):
5757

5858
# hostcontrol
5959
await self.host_control.load()
60-
_LOGGER.info(
61-
"Connected to HostControl. Type: %s Version: %s Hostname: %s "
62-
"Features: %s", self.host_control.type,
63-
self.host_control.version, self.host_control.hostname,
64-
self.host_control.features)
60+
61+
# schedule update info tasks
62+
self.scheduler.register_task(
63+
self.host_control.load, RUN_UPDATE_INFO_TASKS)
6564

6665
# rest api views
6766
self.api.register_host(self.host_control)

hassio/host_control.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, loop):
2929
self.loop = loop
3030
self.active = False
3131
self.version = UNKNOWN
32-
self.last = UNKNOWN
32+
self.last_version = UNKNOWN
3333
self.type = UNKNOWN
3434
self.features = []
3535
self.hostname = UNKNOWN
@@ -57,8 +57,8 @@ async def _send_command(self, command):
5757
writer.write("{}\n".format(command).encode())
5858
data = await reader.readline()
5959

60-
response = data.decode()
61-
_LOGGER.debug("Receive from HostControl: %s.", response)
60+
response = data.decode().rstrip()
61+
_LOGGER.info("Receive from HostControl: %s.", response)
6262

6363
if response == "OK":
6464
return True
@@ -70,7 +70,8 @@ async def _send_command(self, command):
7070
try:
7171
return json.loads(response)
7272
except json.JSONDecodeError:
73-
_LOGGER.warning("Json parse error from HostControl.")
73+
_LOGGER.warning("Json parse error from HostControl '%s'.",
74+
response)
7475

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

9091
self.version = info.get(ATTR_VERSION, UNKNOWN)
91-
self.last = info.get(ATTR_LAST_VERSION, UNKNOWN)
92+
self.last_version = info.get(ATTR_LAST_VERSION, UNKNOWN)
9293
self.type = info.get(ATTR_TYPE, UNKNOWN)
9394
self.features = info.get(ATTR_FEATURES, [])
9495
self.hostname = info.get(ATTR_HOSTNAME, UNKNOWN)

hassio/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
_IMAGE_ARCH = re.compile(r".*/([a-z0-9]*)-hassio-supervisor")
1717

1818

19-
async def fetch_current_versions(websession, beta=False):
19+
async def fetch_last_versions(websession, beta=False):
2020
"""Fetch current versions from github.
2121
2222
Is a coroutine.

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"hassio": "0.19",
2+
"hassio": "0.20",
33
"homeassistant": "0.43.2",
44
"resinos": "0.6",
55
"resinhup": "0.1",

0 commit comments

Comments
 (0)