File: version.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 (42 lines) | stat: -rw-r--r-- 1,272 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
"""Represents the version from the server."""

from __future__ import annotations

from dataclasses import dataclass
from typing import TypedDict


class VersionInfoDataType(TypedDict):
    """Version info data dict type."""

    driverVersion: str
    serverVersion: str
    homeId: int
    minSchemaVersion: int
    maxSchemaVersion: int


@dataclass
class VersionInfo:
    """Version info of the server."""

    driver_version: str
    server_version: str
    home_id: int
    min_schema_version: int
    max_schema_version: int

    @classmethod
    def from_message(cls, msg: VersionInfoDataType) -> VersionInfo:
        """Create a version info from a version message."""
        return cls(
            driver_version=msg["driverVersion"],
            server_version=msg["serverVersion"],
            home_id=msg["homeId"],
            # schema versions are sent in the response from schema version 1+
            # this info not present means the server is at schema version 0
            # at some point in time (when we stop supporting schema version 0),
            # we could adjust this code and assume the keys are there.
            min_schema_version=msg.get("minSchemaVersion", 0),
            max_schema_version=msg.get("maxSchemaVersion", 0),
        )