8000 Migrate triggerlogs to mashumaru (#1277) · python-kasa/python-kasa@0828393 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0828393

Browse files
sdb9696rytilahti
authored andcommitted
Migrate triggerlogs to mashumaru (#1277)
1 parent 74554a2 commit 0828393

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

kasa/smart/modules/triggerlogs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
from __future__ import annotations
44

5-
from datetime import datetime
5+
from dataclasses import dataclass
6+
from typing import Annotated
67

7-
from pydantic.v1 import BaseModel, Field, parse_obj_as
8+
from mashumaro import DataClassDictMixin
9+
from mashumaro.types import Alias
810

911
from ..smartmodule import SmartModule
1012

1113

12-
class LogEntry(BaseModel):
14+
@dataclass
15+
class LogEntry(DataClassDictMixin):
1316
"""Presentation of a single log entry."""
1417

1518
id: int
16-
event_id: str = Field(alias="eventId")
17-
timestamp: datetime
19+
event_id: Annotated[str, Alias("eventId")]
20+
timestamp: int
1821
event: str
1922

2023

@@ -31,4 +34,4 @@ def query(self) -> dict:
3134
@property
3235
def logs(self) -> list[LogEntry]:
3336
"""Return logs."""
34-
return parse_obj_as(list[LogEntry], self.data["logs"])
37+
return [LogEntry.from_dict(log) for log in self.data["logs"]]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from kasa import Device, Module
2+
3+
from ...device_fixtures import parametrize
4+
5+
triggerlogs = parametrize(
6+
"has trigger_logs",
7+
component_filter="trigger_log",
8+
protocol_filter={"SMART", "SMART.CHILD"},
9+
)
10+
11+
12+
@triggerlogs
13+
async def test_trigger_logs(dev: Device):
14+
"""Test that features are registered and work as expected."""
15+
triggerlogs = dev.modules.get(Module.TriggerLogs)
16+
assert triggerlogs is not None
17+
if logs := triggerlogs.logs:
18+
first = logs[0]
19+
assert isinstance(first.id, int)
20+
assert isinstance(first.timestamp, int)
21+
assert isinstance(first.event, str)
22+
assert isinstance(first.event_id, str)

0 commit comments

Comments
 (0)
0