File: discovery.py

package info (click to toggle)
python-aiohasupervisor 0.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 884 kB
  • sloc: python: 4,353; sh: 37; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 1,260 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
"""Discovery client for supervisor."""

from uuid import UUID

from .client import _SupervisorComponentClient
from .const import TIMEOUT_60_SECONDS, ResponseType
from .models.discovery import Discovery, DiscoveryConfig, DiscoveryList, SetDiscovery


class DiscoveryClient(_SupervisorComponentClient):
    """Handles discovery access in supervisor."""

    async def list(self) -> list[Discovery]:
        """List discovered active services."""
        result = await self._client.get("discovery", timeout=TIMEOUT_60_SECONDS)
        return DiscoveryList.from_dict(result.data).discovery

    async def get(self, uuid: UUID) -> Discovery:
        """Get discovery details for a service."""
        result = await self._client.get(f"discovery/{uuid.hex}")
        return Discovery.from_dict(result.data)

    async def delete(self, uuid: UUID) -> None:
        """Remove discovery for a service."""
        await self._client.delete(f"discovery/{uuid.hex}")

    async def set(self, config: DiscoveryConfig) -> UUID:
        """Inform supervisor of an available service."""
        result = await self._client.post(
            "discovery", json=config.to_dict(), response_type=ResponseType.JSON
        )
        return SetDiscovery.from_dict(result.data).uuid