feat(protocols): implement tv_core transport protocols and frozen result models
- Implement WebSocketClosedError preserving Exception.args and str() representation - Implement frozen TvStatus, TvStateSnapshot, CaptureResult, KeysResult, and TextResult dataclasses - Remove Red-phase xfail markers in tests/test_protocols.py
This commit is contained in:
1 parent
712aff354b
commit
72745b85d4
2 files changed
+4
-21
No files matched your search
@@ -8,11 +8,11 @@ from typing import Any, Literal, Protocol
|
|||||||
class WebSocketClosedError(Exception):
|
class WebSocketClosedError(Exception):
|
||||||
"""Raised when a WebSocket transport closes unexpectedly or is already closed."""
|
"""Raised when a WebSocket transport closes unexpectedly or is already closed."""
|
||||||
|
|
||||||
code: int
|
|
||||||
reason: str
|
|
||||||
|
|
||||||
def __init__(self, code: int, reason: str = "") -> None:
|
def __init__(self, code: int, reason: str = "") -> None:
|
||||||
raise NotImplementedError
|
message = f"WebSocket closed ({code}): {reason}" if reason else f"WebSocket closed ({code})"
|
||||||
|
super().__init__(message)
|
||||||
|
self.code = code
|
||||||
|
self.reason = reason
|
||||||
|
|
||||||
|
|
||||||
class WebSocketTransport(Protocol):
|
class WebSocketTransport(Protocol):
|
||||||
@@ -61,9 +61,6 @@ class TvStatus:
|
|||||||
status: Literal["connected", "already_connected"]
|
status: Literal["connected", "already_connected"]
|
||||||
elapsed_ms: int
|
elapsed_ms: int
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class TvStateSnapshot:
|
class TvStateSnapshot:
|
||||||
@@ -77,9 +74,6 @@ class TvStateSnapshot:
|
|||||||
foreground_app: str | None
|
foreground_app: str | None
|
||||||
last_updated: float | None
|
last_updated: float | None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class CaptureResult:
|
class CaptureResult:
|
||||||
@@ -90,9 +84,6 @@ class CaptureResult:
|
|||||||
changed_since_last: bool
|
changed_since_last: bool
|
||||||
size_bytes: int
|
size_bytes: int
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class KeysResult:
|
class KeysResult:
|
||||||
@@ -105,9 +96,6 @@ class KeysResult:
|
|||||||
size_bytes: int | None = None
|
size_bytes: int | None = None
|
||||||
capture_error: str | None = None
|
capture_error: str | None = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, slots=True)
|
@dataclass(frozen=True, slots=True)
|
||||||
class TextResult:
|
class TextResult:
|
||||||
@@ -119,6 +107,3 @@ class TextResult:
|
|||||||
changed_since_last: bool | None = None
|
changed_since_last: bool | None = None
|
||||||
size_bytes: int | None = None
|
size_bytes: int | None = None
|
||||||
capture_error: str | None = None
|
capture_error: str | None = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
raise NotImplementedError
|
|
||||||
@@ -12,7 +12,6 @@ from lg_smtv_mcp.tv_core.protocols import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=True, reason="Red phase: protocols")
|
|
||||||
def test_websocket_closed_error_preserves_args_and_str_representation() -> None:
|
def test_websocket_closed_error_preserves_args_and_str_representation() -> None:
|
||||||
err = WebSocketClosedError(1008, "Try Again Later (EWS)")
|
err = WebSocketClosedError(1008, "Try Again Later (EWS)")
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ def test_websocket_closed_error_preserves_args_and_str_representation() -> None:
|
|||||||
assert "1000" in str(err_no_reason)
|
assert "1000" in str(err_no_reason)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=True, reason="Red phase: protocols")
|
|
||||||
def test_result_dataclasses_are_frozen_and_expose_expected_fields() -> None:
|
def test_result_dataclasses_are_frozen_and_expose_expected_fields() -> None:
|
||||||
status = TvStatus(status="connected", elapsed_ms=120)
|
status = TvStatus(status="connected", elapsed_ms=120)
|
||||||
snapshot = TvStateSnapshot(
|
snapshot = TvStateSnapshot(
|
||||||
|
|||||||
Reference in new issue
Block a user