File: __init__.py

package info (click to toggle)
zwave-js-server-python 0.67.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,820 kB
  • sloc: python: 15,886; sh: 21; javascript: 16; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,233 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
37
38
39
40
41
42
43
44
45
46
47
"""
Model for Z-Wave JS config manager.

https://zwave-js.github.io/node-zwave-js/#/api/config-manager
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from ..device_config import DeviceConfig

if TYPE_CHECKING:
    from ...client import Client


class ConfigManager:
    """Model for the Z-Wave JS config manager."""

    def __init__(self, client: Client) -> None:
        """Initialize."""
        self._client = client

    async def lookup_device(
        self,
        manufacturer_id: int,
        product_type: int,
        product_id: int,
        firmware_version: str | None = None,
    ) -> DeviceConfig | None:
        """Look up the definition of a given device in the configuration DB."""
        cmd: dict[str, Any] = {
            "command": "config_manager.lookup_device",
            "manufacturerId": manufacturer_id,
            "productType": product_type,
            "productId": product_id,
        }

        if firmware_version is not None:
            cmd["firmwareVersion"] = firmware_version

        data = await self._client.async_send_command(cmd)

        if not data or not (config := data.get("config")):
            return None

        return DeviceConfig(config)