Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyhap/accessory_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
PROP_PERMISSIONS,
Characteristic,
CharacteristicError,
CharacteristicWrite,
HAPValue,
)
from pyhap.const import (
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.

Expand Down
23 changes: 22 additions & 1 deletion pyhap/characteristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that you can pass total to control if fields are opt or not. 👍

"""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"
Expand Down
Loading