File: supervisor.py

package info (click to toggle)
python-aiohasupervisor 0.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 932 kB
  • sloc: python: 4,666; sh: 37; makefile: 3
file content (63 lines) | stat: -rw-r--r-- 2,137 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Supervisor client for supervisor."""

from aiohttp import ClientTimeout

from .client import _SupervisorComponentClient
from .const import ResponseType
from .models.supervisor import (
    SupervisorInfo,
    SupervisorOptions,
    SupervisorStats,
    SupervisorUpdateOptions,
)


class SupervisorManagementClient(_SupervisorComponentClient):
    """Handles supervisor access in supervisor."""

    async def ping(self) -> None:
        """Check connection to supervisor."""
        await self._client.get(
            "supervisor/ping",
            response_type=ResponseType.NONE,
            timeout=ClientTimeout(total=15),
        )

    async def info(self) -> SupervisorInfo:
        """Get supervisor info."""
        result = await self._client.get("supervisor/info")
        return SupervisorInfo.from_dict(result.data)

    async def stats(self) -> SupervisorStats:
        """Get supervisor stats."""
        result = await self._client.get("supervisor/stats")
        return SupervisorStats.from_dict(result.data)

    async def update(self, options: SupervisorUpdateOptions | None = None) -> None:
        """Update supervisor.

        Providing a target version in options only works on development systems.
        On non-development systems this API will always update supervisor to the
        latest version and ignore that field.
        """
        await self._client.post(
            "supervisor/update",
            json=options.to_dict() if options else None,
            timeout=None,
        )

    async def reload(self) -> None:
        """Reload supervisor (add-ons, configuration, etc)."""
        await self._client.post("supervisor/reload")

    async def restart(self) -> None:
        """Restart supervisor."""
        await self._client.post("supervisor/restart")

    async def set_options(self, options: SupervisorOptions) -> None:
        """Set supervisor options."""
        await self._client.post("supervisor/options", json=options.to_dict())

    async def repair(self) -> None:
        """Repair local supervisor and docker setup."""
        await self._client.post("supervisor/repair")