Add support for cleaning records (#945)
Some checks are pending
CI / Perform linting checks (3.13) (push) Waiting to run
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.13) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.13) (push) Blocked by required conditions
CodeQL checks / Analyze (python) (push) Waiting to run

Co-authored-by: Steven B. <51370195+sdb9696@users.noreply.github.com>
This commit is contained in:
Teemu R.
2025-01-20 12:41:56 +01:00
committed by GitHub
parent bca5576425
commit 05085462d3
12 changed files with 448 additions and 15 deletions

View File

@@ -0,0 +1,59 @@
from __future__ import annotations
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
import pytest
from kasa import Module
from kasa.smart import SmartDevice
from ...device_fixtures import get_parent_and_child_modules, parametrize
cleanrecords = parametrize(
"has clean records", component_filter="clean_percent", protocol_filter={"SMART"}
)
@cleanrecords
@pytest.mark.parametrize(
("feature", "prop_name", "type"),
[
("total_clean_area", "total_clean_area", int),
("total_clean_time", "total_clean_time", timedelta),
("last_clean_area", "last_clean_area", int),
("last_clean_time", "last_clean_time", timedelta),
("total_clean_count", "total_clean_count", int),
("last_clean_timestamp", "last_clean_timestamp", datetime),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
"""Test that features are registered and work as expected."""
records = next(get_parent_and_child_modules(dev, Module.CleanRecords))
assert records is not None
prop = getattr(records, prop_name)
assert isinstance(prop, type)
feat = records._device.features[feature]
assert feat.value == prop
assert isinstance(feat.value, type)
@cleanrecords
async def test_timezone(dev: SmartDevice):
"""Test that timezone is added to timestamps."""
clean_records = next(get_parent_and_child_modules(dev, Module.CleanRecords))
assert clean_records is not None
assert isinstance(clean_records.last_clean_timestamp, datetime)
assert clean_records.last_clean_timestamp.tzinfo
# Check for zone info to ensure that this wasn't picking upthe default
# of utc before the time module is updated.
assert isinstance(clean_records.last_clean_timestamp.tzinfo, ZoneInfo)
for record in clean_records.parsed_data.records:
assert isinstance(record.timestamp, datetime)
assert record.timestamp.tzinfo
assert isinstance(record.timestamp.tzinfo, ZoneInfo)