diff --git a/pyhap/accessory_driver.py b/pyhap/accessory_driver.py index 9a73f8ed..58b2e791 100644 --- a/pyhap/accessory_driver.py +++ b/pyhap/accessory_driver.py @@ -45,6 +45,7 @@ PROP_PERMISSIONS, Characteristic, CharacteristicError, + CharacteristicWrite, HAPValue, ) from pyhap.const import ( @@ -1239,7 +1240,7 @@ def _run_characteristic_writes( client_uuid: UUID | None, pending: list[_PendingWrite], ) -> tuple[dict[int, dict[int, dict[str, Any]]], list[_PendingWrite]]: - queries: list[dict[str, Any]] = chars_query[HAP_REPR_CHARS] + queries: list[CharacteristicWrite] = chars_query[HAP_REPR_CHARS] timed_write = HAP_REPR_PID in chars_query if timed_write and not self._take_prepared_write( @@ -1593,7 +1594,7 @@ def signal_handler(self, _signal: Any, _frame: Any) -> None: raise def _notify( - self, queries: list[dict[str, Any]], client_addr: tuple[str, int] + self, queries: list[CharacteristicWrite], client_addr: tuple[str, int] ) -> set[tuple[int, int]]: """Notify the driver that the client has subscribed or unsubscribed. diff --git a/pyhap/characteristic.py b/pyhap/characteristic.py index 19a2730e..0e757c0f 100644 --- a/pyhap/characteristic.py +++ b/pyhap/characteristic.py @@ -7,7 +7,7 @@ from collections.abc import Callable import inspect import logging -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, TypedDict from uuid import UUID from .const import ( @@ -50,6 +50,27 @@ def _setter_wants_client_addr(setter: Callable[..., Any]) -> bool: # A characteristic value as HAP JSON carries it. HAPValue = bool | int | float | str | None + +class _CharacteristicWriteTarget(TypedDict): + aid: int + iid: int + + +class CharacteristicWrite(_CharacteristicWriteTarget, total=False): + """One characteristic of a write, as HAP JSON carries it. + + ``value`` is the value to write, ``ev`` subscribes or unsubscribes and + ``r`` asks for a write response. ``authData`` and ``remote`` are part of + the HAP request too, the driver does not read them. + """ + + value: HAPValue + ev: bool + r: bool + authData: str + remote: bool + + HAP_FORMAT_BOOL = "bool" HAP_FORMAT_INT = "int" HAP_FORMAT_FLOAT = "float"