Skip to content

Commit bfa7443

Browse files
authored
Merge pull request #97 from home-assistant/dev
Release 0.43
2 parents 7e5b267 + 253962d commit bfa7443

File tree

20 files changed

+428
-211
lines changed

20 files changed

+428
-211
lines changed

API.md

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,48 +51,13 @@ The addons from `addons` are only installed one.
5151
],
5252
"addons_repositories": [
5353
"REPO_URL"
54-
],
55-
"snapshots": [
56-
{
57-
"slug": "SLUG",
58-
"data": "ISO",
59-
"name": "Custom name"
60-
}
6154
]
6255
}
6356
```
6457

6558
- GET `/supervisor/addons`
6659

67-
Get all available addons
68-
69-
```json
70-
{
71-
"addons": [
72-
{
73-
"name": "xy bla",
74-
"slug": "xy",
75-
"description": "description",
76-
"arch": ["armhf", "aarch64", "i386", "amd64"],
77-
"repository": "core|local|REP_ID",
78-
"version": "LAST_VERSION",
79-
"installed": "none|INSTALL_VERSION",
80-
"detached": "bool",
81-
"build": "bool",
82-
"url": "null|url"
83-
}
84-
],
85-
"repositories": [
86-
{
87-
"slug": "12345678",
88-
"name": "Repitory Name|unknown",
89-
"source": "URL_OF_REPOSITORY",
90-
"url": "WEBSITE|REPOSITORY",
91-
"maintainer": "BLA BLU <[email protected]>|unknown"
92-
}
93-
]
94-
}
95-
```
60+
Get all available addons. Will be delete soon. Look to `/addons`
9661

9762
- POST `/supervisor/update`
9863
Optional:
@@ -157,6 +122,21 @@ Return QR-Code
157122

158123
### Backup/Snapshot
159124

125+
- GET `/snapshots`
126+
```json
127+
{
128+
"snapshots": [
129+
{
130+
"slug": "SLUG",
131+
"date": "ISO",
132+
"name": "Custom name"
133+
}
134+
]
135+
}
136+
```
137+
138+
- POST `/snapshots/reload`
139+
160140
- POST `/snapshots/new/full`
161141
```json
162142
{
@@ -269,7 +249,9 @@ Optional:
269249
{
270250
"version": "INSTALL_VERSION",
271251
"last_version": "LAST_VERSION",
272-
"devices": []
252+
"devices": [""],
253+
"image": "str",
254+
"custom": "bool -> if custom image"
273255
}
274256
```
275257

@@ -291,11 +273,47 @@ Output the raw docker log
291273
```json
292274
{
293275
"devices": [],
276+
"image": "Optional|null",
277+
"last_version": "Optional for custom image|null"
294278
}
295279
```
296280

281+
Image with `null` and last_version with `null` reset this options.
282+
297283
### REST API addons
298284

285+
- GET `/addons`
286+
287+
Get all available addons
288+
289+
```json
290+
{
291+
"addons": [
292+
{
293+
"name": "xy bla",
294+
"slug": "xy",
295+
"description": "description",
296+
"arch": ["armhf", "aarch64", "i386", "amd64"],
297+
"repository": "core|local|REP_ID",
298+
"version": "LAST_VERSION",
299+
"installed": "none|INSTALL_VERSION",
300+
"detached": "bool",
301+
"build": "bool",
302+
"url": "null|url"
303+
}
304+
],
305+
"repositories": [
306+
{
307+
"slug": "12345678",
308+
"name": "Repitory Name|unknown",
309+
"source": "URL_OF_REPOSITORY",
310+
"url": "WEBSITE|REPOSITORY",
311+
"maintainer": "BLA BLU <[email protected]>|unknown"
312+
}
313+
]
314+
}
315+
```
316+
299317
- POST `/addons/reload`
300318

301319
- GET `/addons/{addon}/info`

hassio/addons/data.py

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,22 @@
1515
from ..const import (
1616
FILE_HASSIO_ADDONS, ATTR_VERSION, ATTR_SLUG, ATTR_REPOSITORY, ATTR_LOCATON,
1717
REPOSITORY_CORE, REPOSITORY_LOCAL, ATTR_USER, ATTR_SYSTEM)
18-
from ..tools import read_json_file, write_json_file
18+
from ..tools import JsonConfig, read_json_file
1919

2020
_LOGGER = logging.getLogger(__name__)
2121

2222
RE_VOLUME = re.compile(MAP_VOLUME)
2323

2424

25-
class Data(object):
25+
class Data(JsonConfig):
2626
"""Hold data for addons inside HassIO."""
2727

2828
def __init__(self, config):
2929
"""Initialize data holder."""
30-
self._file = FILE_HASSIO_ADDONS
31-
self._data = {}
30+
super().__init__(FILE_HASSIO_ADDONS, SCHEMA_ADDON_FILE)
3231
self.config = config
33-
self._cache = {}
3432
self._repositories = {}
35-
36-
# init or load data
37-
if self._file.is_file():
38-
try:
39-
self._data = read_json_file(self._file)
40-
except (OSError, json.JSONDecodeError):
41-
_LOGGER.warning("Can't read %s", self._file)
42-
self._data = {}
43-
44-
# validate
45-
try:
46-
self._data = SCHEMA_ADDON_FILE(self._data)
47-
except vol.Invalid as ex:
48-
_LOGGER.error("Can't parse addons.json -> %s",
49-
humanize_error(self._data, ex))
50-
51-
def save(self):
52-
"""Store data to config file."""
53-
# validate
54-
try:
55-
self._data = SCHEMA_ADDON_FILE(self._data)
56-
except vol.Invalid as ex:
57-
_LOGGER.error("Can't parse addons data -> %s",
58-
humanize_error(self._data, ex))
59-
return False
60-
61-
if not write_json_file(self._file, self._data):
62-
_LOGGER.error("Can't store config in %s", self._file)
63-
return False
64-
return True
33+
self._cache = {}
6534

6635
@property
6736
def user(self):

hassio/api/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def register_addons(self, addons):
7777
"""Register homeassistant function."""
7878
api_addons = APIAddons(self.config, self.loop, addons)
7979

80+
self.webapp.router.add_get('/addons', api_addons.list)
81+
self.webapp.router.add_post('/addons/reload', api_addons.reload)
82+
8083
self.webapp.router.add_get('/addons/{addon}/info', api_addons.info)
8184
self.webapp.router.add_post(
8285
'/addons/{addon}/install', api_addons.install)
@@ -105,6 +108,9 @@ def register_snapshots(self, snapshots):
105108
"""Register snapshots function."""
106109
api_snapshots = APISnapshots(self.config, self.loop, snapshots)
107110

111+
self.webapp.router.add_get('/snapshots', api_snapshots.list)
112+
self.webapp.router.add_post('/snapshots/reload', api_snapshots.reload)
113+
108114
self.webapp.router.add_post(
109115
'/snapshots/new/full', api_snapshots.snapshot_full)
110116
self.webapp.router.add_post(

hassio/api/addons.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from ..const import (
1010
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_STATE, ATTR_BOOT, ATTR_OPTIONS,
1111
ATTR_URL, ATTR_DESCRIPTON, ATTR_DETACHED, ATTR_NAME, ATTR_REPOSITORY,
12-
ATTR_BUILD, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_HOST_NETWORK,
13-
BOOT_AUTO, BOOT_MANUAL)
12+
ATTR_BUILD, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_HOST_NETWORK, ATTR_SLUG,
13+
ATTR_SOURCE, ATTR_REPOSITORIES, ATTR_ADDONS, ATTR_ARCH, ATTR_MAINTAINER,
14+
ATTR_INSTALLED, BOOT_AUTO, BOOT_MANUAL)
1415
from ..validate import DOCKER_PORTS
1516

1617
_LOGGER = logging.getLogger(__name__)
@@ -47,6 +48,44 @@ def _extract_addon(self, request, check_installed=True):
4748

4849
return addon
4950

51+
@api_process
52+
async def list(self, request):
53+
"""Return all addons / repositories ."""
54+
data_addons = []
55+
for addon in self.addons.list_addons:
56+
data_addons.append({
57+
ATTR_NAME: addon.name,
58+
ATTR_SLUG: addon.slug,
59+
ATTR_DESCRIPTON: addon.description,
60+
ATTR_VERSION: addon.last_version,
61+
ATTR_INSTALLED: addon.version_installed,
62+
ATTR_ARCH: addon.supported_arch,
63+
ATTR_DETACHED: addon.is_detached,
64+
ATTR_REPOSITORY: addon.repository,
65+
ATTR_BUILD: addon.need_build,
66+
ATTR_URL: addon.url,
67+
})
68+
69+
data_repositories = []
70+
for repository in self.addons.list_repositories:
71+
data_repositories.append({
72+
ATTR_SLUG: repository.slug,
73+
ATTR_NAME: repository.name,
74+
ATTR_SOURCE: repository.source,
75+
ATTR_URL: repository.url,
76+
ATTR_MAINTAINER: repository.maintainer,
77+
})
78+
79+
return {
80+
ATTR_ADDONS: data_addons,
81+
ATTR_REPOSITORIES: data_repositories,
82+
}
83+
84+
@api_process
85+
def reload(self, request):
86+
"""Reload all addons data."""
87+
return self.addons.reload()
88+
5089
@api_process
5190
async def info(self, request):
5291
"""Return addon information."""

hassio/api/homeassistant.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
import voluptuous as vol
66

77
from .util import api_process, api_process_raw, api_validate
8-
from ..const import ATTR_VERSION, ATTR_LAST_VERSION, ATTR_DEVICES
8+
from ..const import (
9+
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_DEVICES, ATTR_IMAGE, ATTR_CUSTOM)
910
from ..validate import HASS_DEVICES
1011

1112
_LOGGER = logging.getLogger(__name__)
1213

1314

1415
SCHEMA_OPTIONS = vol.Schema({
1516
vol.Optional(ATTR_DEVICES): HASS_DEVICES,
17+
vol.Inclusive(ATTR_IMAGE, 'custom_hass'): vol.Any(None, vol.Coerce(str)),
18+
vol.Inclusive(ATTR_LAST_VERSION, 'custom_hass'):
19+
vol.Any(None, vol.Coerce(str)),
1620
})
1721

1822
SCHEMA_VERSION = vol.Schema({
@@ -34,8 +38,10 @@ async def info(self, request):
3438
"""Return host information."""
3539
return {
3640
ATTR_VERSION: self.homeassistant.version,
37-
ATTR_LAST_VERSION: self.config.last_homeassistant,
38-
ATTR_DEVICES: self.config.homeassistant_devices,
41+
ATTR_LAST_VERSION: self.homeassistant.last_version,
42+
ATTR_IMAGE: self.homeassistant.image,
43+
ATTR_DEVICES: self.homeassistant.devices,
44+
ATTR_CUSTOM: self.homeassistant.is_custom_image,
3945
}
4046

4147
@api_process
@@ -44,7 +50,11 @@ async def options(self, request):
4450
body = await api_validate(SCHEMA_OPTIONS, request)
4551

4652
if ATTR_DEVICES in body:
47-
self.config.homeassistant_devices = body[ATTR_DEVICES]
53+
self.homeassistant.devices = body[ATTR_DEVICES]
54+
55+
if ATTR_IMAGE in body:
56+
self.homeassistant.set_custom(
57+
body[ATTR_IMAGE], body[ATTR_LAST_VERSION])
4858

4959
return True
5060

@@ -57,9 +67,6 @@ async def update(self, request):
5767
if self.homeassistant.in_progress:
5868
raise RuntimeError("Other task is in progress")
5969

60-
if version == self.homeassistant.version:
61-
raise RuntimeError("Version is already in use")
62-
6370
return await asyncio.shield(
6471
self.homeassistant.update(version), loop=self.loop)
6572

hassio/api/snapshots.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..const import (
1010
ATTR_NAME, ATTR_SLUG, ATTR_DATE, ATTR_ADDONS, ATTR_REPOSITORIES,
1111
ATTR_HOMEASSISTANT, ATTR_VERSION, ATTR_SIZE, ATTR_FOLDERS, ATTR_TYPE,
12-
ATTR_DEVICES)
12+
ATTR_DEVICES, ATTR_SNAPSHOTS)
1313

1414
_LOGGER = logging.getLogger(__name__)
1515

@@ -47,23 +47,39 @@ def _extract_snapshot(self, request):
4747
raise RuntimeError("Snapshot not exists")
4848
return snapshot
4949

50-
@staticmethod
51-
def _addons_list(snapshot):
52-
"""Generate a list with addons data."""
53-
data = []
54-
for addon_data in snapshot.addons:
55-
data.append({
56-
ATTR_SLUG: addon_data[ATTR_SLUG],
57-
ATTR_NAME: addon_data[ATTR_NAME],
58-
ATTR_VERSION: addon_data[ATTR_VERSION],
50+
@api_process
51+
async def list(self, request):
52+
"""Return snapshot list."""
53+
data_snapshots = []
54+
for snapshot in self.snapshots.list_snapshots:
55+
data_snapshots.append({
56+
ATTR_SLUG: snapshot.slug,
57+
ATTR_NAME: snapshot.name,
58+
ATTR_DATE: snapshot.date,
5959
})
60-
return data
60+
61+
return {
62+
ATTR_SNAPSHOTS: data_snapshots,
63+
}
64+
65+
@api_process
66+
def reload(self, request):
67+
"""Reload snapshot list."""
68+
return asyncio.shield(self.snapshots.reload(), loop=self.loop)
6169

6270
@api_process
6371
async def info(self, request):
6472
"""Return snapshot info."""
6573
snapshot = self._extract_snapshot(request)
6674

75+
data_addons = []
76+
for addon_data in snapshot.addons:
77+
data_addons.append({
78+
ATTR_SLUG: addon_data[ATTR_SLUG],
79+
ATTR_NAME: addon_data[ATTR_NAME],
80+
ATTR_VERSION: addon_data[ATTR_VERSION],
81+
})
82+
6783
return {
6884
ATTR_SLUG: snapshot.slug,
6985
ATTR_TYPE: snapshot.sys_type,
@@ -74,7 +90,7 @@ async def info(self, request):
7490
ATTR_VERSION: snapshot.homeassistant_version,
7591
ATTR_DEVICES: snapshot.homeassistant_devices,
7692
},
77-
ATTR_ADDONS: self._addons_list(snapshot),
93+
ATTR_ADDONS: data_addons,
7894
ATTR_REPOSITORIES: snapshot.repositories,
7995
ATTR_FOLDERS: snapshot.folders,
8096
}

0 commit comments

Comments
 (0)