File: controller.py

package info (click to toggle)
python-aiohomekit 3.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,620 kB
  • sloc: python: 16,560; sh: 14; makefile: 8
file content (36 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download
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
from __future__ import annotations

from typing import Any

from aiohomekit.controller.abstract import TransportType
from aiohomekit.controller.ip.discovery import IpDiscovery
from aiohomekit.controller.ip.pairing import IpPairing
from aiohomekit.zeroconf import HAP_TYPE_TCP, ZeroconfController


class IpController(ZeroconfController):
    hap_type = HAP_TYPE_TCP
    discoveries: dict[str, IpDiscovery]
    pairings: dict[str, IpPairing]
    transport_type = TransportType.IP

    def _make_discovery(self, discovery) -> IpDiscovery:
        return IpDiscovery(self, discovery)

    def load_pairing(
        self, alias: str, pairing_data: dict[str, Any]
    ) -> IpPairing | None:
        if pairing_data["Connection"] != "IP":
            return None

        if not (hkid := pairing_data.get("AccessoryPairingID")):
            return None

        pairing = self.pairings[hkid.lower()] = IpPairing(self, pairing_data)

        if discovery := self.discoveries.get(hkid.lower()):
            pairing._async_description_update(discovery.description)

        self.aliases[alias] = pairing

        return pairing