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
10 changes: 10 additions & 0 deletions kasa/cli/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,13 @@
click.confirm("Do you really want to replace the existing credentials?", abort=True)

return await dev.update_credentials(username, password)


@device.command(name="logs")
@pass_dev_or_child
async def child_logs(dev):
"""Print child device trigger logs."""
if logs := dev.modules.get(Module.TriggerLogs):
await dev.update(update_children=True)

Check warning on line 203 in kasa/cli/device.py

View check run for this annotation

Codecov / codecov/patch

kasa/cli/device.py#L203

Added line #L203 was not covered by tests
for entry in logs.logs:
print(entry)

Check warning on line 205 in kasa/cli/device.py

View check run for this annotation

Codecov / codecov/patch

kasa/cli/device.py#L205

Added line #L205 was not covered by tests
1 change: 1 addition & 0 deletions kasa/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Module(ABC):
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = ModuleName(
"WaterleakSensor"
)
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = ModuleName("TriggerLogs")

# SMARTCAMERA only modules
Camera: Final[ModuleName[experimental.Camera]] = ModuleName("Camera")
Expand Down
2 changes: 2 additions & 0 deletions kasa/smart/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .temperaturecontrol import TemperatureControl
from .temperaturesensor import TemperatureSensor
from .time import Time
from .triggerlogs import TriggerLogs
from .waterleaksensor import WaterleakSensor

__all__ = [
Expand Down Expand Up @@ -56,6 +57,7 @@
"WaterleakSensor",
"ContactSensor",
"MotionSensor",
"TriggerLogs",
"FrostProtection",
"SmartLightEffect",
]
34 changes: 34 additions & 0 deletions kasa/smart/modules/triggerlogs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Implementation of trigger logs module."""

from __future__ import annotations

from datetime import datetime

from pydantic.v1 import BaseModel, Field, parse_obj_as

from ..smartmodule import SmartModule


class LogEntry(BaseModel):
"""Presentation of a single log entry."""

id: int
event_id: str = Field(alias="eventId")
timestamp: datetime
event: str


class TriggerLogs(SmartModule):
"""Implementation of trigger logs."""

REQUIRED_COMPONENT = "trigger_log"
MINIMUM_UPDATE_INTERVAL_SECS = 60 * 60

def query(self) -> dict:
"""Query to execute during the update cycle."""
return {"get_trigger_logs": {"start_id": 0}}

@property
def logs(self) -> list[LogEntry]:
"""Return logs."""
return parse_obj_as(list[LogEntry], self.data["logs"])

Check warning on line 34 in kasa/smart/modules/triggerlogs.py

View check run for this annotation

Codecov / codecov/patch

kasa/smart/modules/triggerlogs.py#L34

Added line #L34 was not covered by tests
Loading