Skip to content

Commit 50c9729

Browse files
authored
Add store APIs to client (#7)
1 parent 01e91fc commit 50c9729

File tree

11 files changed

+4009
-1
lines changed

11 files changed

+4009
-1
lines changed

aiohasupervisor/models/addons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Models for Supervisor."""
1+
"""Models for Supervisor addons."""
22

33
from abc import ABC
44
from dataclasses import dataclass, field

aiohasupervisor/root.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .addons import AddonsClient
88
from .client import _SupervisorClient
99
from .models.root import AvailableUpdate, AvailableUpdates, RootInfo
10+
from .store import StoreClient
1011

1112

1213
class SupervisorClient:
@@ -22,12 +23,18 @@ def __init__(
2223
"""Initialize client."""
2324
self._client = _SupervisorClient(api_host, token, request_timeout, session)
2425
self._addons = AddonsClient(self._client)
26+
self._store = StoreClient(self._client)
2527

2628
@property
2729
def addons(self) -> AddonsClient:
2830
"""Get addons component client."""
2931
return self._addons
3032

33+
@property
34+
def store(self) -> StoreClient:
35+
"""Get store component client."""
36+
return self._store
37+
3138
async def info(self) -> RootInfo:
3239
"""Get root info."""
3340
result = await self._client.get("info")

aiohasupervisor/store.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""Store client for supervisor."""
2+
3+
from .client import _SupervisorComponentClient
4+
from .const import ResponseType
5+
from .models.addons import (
6+
Repository,
7+
StoreAddon,
8+
StoreAddonComplete,
9+
StoreAddonsList,
10+
StoreAddonUpdate,
11+
StoreAddRepository,
12+
StoreInfo,
13+
)
14+
15+
16+
class StoreClient(_SupervisorComponentClient):
17+
"""Handles store access in Supervisor."""
18+
19+
async def info(self) -> StoreInfo:
20+
"""Get store info."""
21+
result = await self._client.get("store")
22+
return StoreInfo.from_dict(result.data)
23+
24+
async def addons_list(self) -> list[StoreAddon]:
25+
"""Get list of store addons."""
26+
result = await self._client.get("store/addons")
27+
return StoreAddonsList.from_dict(result.data).addons
28+
29+
async def addon_info(self, addon: str) -> StoreAddonComplete:
30+
"""Get store addon info."""
31+
result = await self._client.get(f"store/addons/{addon}")
32+
return StoreAddonComplete.from_dict(result.data)
33+
34+
async def addon_changelog(self, addon: str) -> str:
35+
"""Get addon changelog."""
36+
result = await self._client.get(
37+
f"store/addons/{addon}/changelog", response_type=ResponseType.TEXT
38+
)
39+
return result.data
40+
41+
async def addon_documentation(self, addon: str) -> str:
42+
"""Get addon documentation."""
43+
result = await self._client.get(
44+
f"store/addons/{addon}/documentation", response_type=ResponseType.TEXT
45+
)
46+
return result.data
47+
48+
async def install_addon(self, addon: str) -> None:
49+
"""Install an addon."""
50+
await self._client.post(f"store/addons/{addon}/install")
51+
52+
async def update_addon(
53+
self, addon: str, options: StoreAddonUpdate | None = None
54+
) -> None:
55+
"""Update an addon to latest version."""
56+
await self._client.post(
57+
f"store/addons/{addon}/update", json=options.to_dict() if options else None
58+
)
59+
60+
async def reload(self) -> None:
61+
"""Reload the store."""
62+
await self._client.post("store/reload")
63+
64+
async def repositories_list(self) -> list[Repository]:
65+
"""Get list of repositories."""
66+
result = await self._client.get("store/repositories")
67+
# This API is inconsistent with Supervisor's API model, data should be
68+
# a dictionary with a "repositories" field. It would break the CLI like
69+
# this but the CLI doesn't use it so it went unnoticed.
70+
return [Repository.from_dict(repo) for repo in result.data]
71+
72+
async def repository_info(self, repository: str) -> Repository:
73+
"""Get repository info."""
74+
result = await self._client.get(f"store/repositories/{repository}")
75+
return Repository.from_dict(result.data)
76+
77+
async def add_repository(self, options: StoreAddRepository) -> None:
78+
"""Add a repository to the store."""
79+
await self._client.post("store/repositories", json=options.to_dict())
80+
81+
async def remove_repository(self, repository: str) -> None:
82+
"""Remove a repository from the store."""
83+
await self._client.delete(f"store/repositories/{repository}")
84+
85+
# Omitted for now - Icon/Logo endpoints
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Changelog
2+
3+
## 6.4.1
4+
5+
- Increase default max_queued_messages to 8192 to fix dropped messages during Home Assistant startup
6+
7+
## 6.4.0
8+
9+
- Update mosquitto to 2.0.18
10+
11+
## 6.3.1
12+
13+
- Add ability to use a pre-hashed password for custom logins
14+
15+
## 6.3.0
16+
17+
- Update mosquitto to 2.0.17
18+
19+
## 6.2.1
20+
21+
- Add explicit dependencies for dynamic security plugin and asynchronous name resolver
22+
23+
## 6.2.0
24+
25+
- Update mosquitto to 2.0.15
26+
- Update libwebsockets to 4.3.2 (fixes Unable to create websockets listener)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Home Assistant Add-on: Mosquitto broker
2+
3+
## Installation
4+
5+
Follow these steps to get the add-on installed on your system:
6+
7+
1. Navigate in your Home Assistant frontend to **Settings** -> **Add-ons** -> **Add-on store**.
8+
2. Find the "Mosquitto broker" add-on and click it.
9+
3. Click on the "INSTALL" button.
10+
11+
## How to use
12+
13+
The add-on has a couple of options available. To get the add-on running:
14+
15+
1. Start the add-on.
16+
2. Have some patience and wait a couple of minutes.
17+
3. Check the add-on log output to see the result.
18+
19+
Create a new user for MQTT via your Home Assistant's frontend **Settings** -> **People** -> **Users** , (i.e. not on Mosquitto's **Configuration** tab).
20+
Notes:
21+
22+
1. This name cannot be `homeassistant` or `addons`, those are reserved usernames.
23+
2. If you do not see the option to create a new user, ensure that **Advanced Mode** is enabled in your Home Assistant profile.
24+
25+
To use the Mosquitto as a broker, go to the integration page and install the configuration with one click:
26+
27+
1. Navigate in your Home Assistant frontend to **Settings** -> **Devices & Services** -> **Integrations**.
28+
2. MQTT should appear as a discovered integration at the top of the page
29+
3. Select it and check the box to enable MQTT discovery if desired, and hit submit.
30+
31+
If you have old MQTT settings available, remove this old integration and restart Home Assistant to see the new one.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"result": "ok",
3+
"data": {
4+
"advanced": false,
5+
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
6+
"available": true,
7+
"build": false,
8+
"description": "An Open Source MQTT broker",
9+
"documentation": true,
10+
"homeassistant": null,
11+
"icon": true,
12+
"installed": true,
13+
"logo": true,
14+
"name": "Mosquitto broker",
15+
"repository": "core",
16+
"slug": "core_mosquitto",
17+
"stage": "stable",
18+
"update_available": false,
19+
"url": "https://github.com/home-assistant/addons/tree/master/mosquitto",
20+
"version_latest": "6.4.1",
21+
"version": "6.4.1",
22+
"apparmor": "default",
23+
"auth_api": true,
24+
"detached": false,
25+
"docker_api": false,
26+
"full_access": false,
27+
"hassio_api": false,
28+
"hassio_role": "default",
29+
"homeassistant_api": false,
30+
"host_network": false,
31+
"host_pid": false,
32+
"ingress": false,
33+
"long_description": "# Home Assistant Add-on: Mosquitto broker\n\nMQTT broker for Home Assistant.\n\n![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield]\n\n## About\n\nYou can use this add-on to install Eclipse Mosquitto, which is an open-source (EPL/EDL licensed) message broker that implements the MQTT protocol. Mosquitto is lightweight and is suitable for use on all devices from low power single board computers to full servers. For more information, please see [mosquitto].\n\n[mosquitto]: https://mosquitto.org\n[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg\n[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg\n[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg\n[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg\n[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg\n",
34+
"rating": 7,
35+
"signed": true
36+
}
37+
}

0 commit comments

Comments
 (0)