mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
ba273f308e
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
Ensures no error with devices that do not have the `lens_mask` component.
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""Tests for smart camera devices."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
import pytest
|
|
from freezegun.api import FrozenDateTimeFactory
|
|
|
|
from kasa import Device, DeviceType, Module
|
|
|
|
from ..conftest import device_smartcam, hub_smartcam
|
|
|
|
|
|
@device_smartcam
|
|
async def test_state(dev: Device):
|
|
if dev.device_type is DeviceType.Hub:
|
|
pytest.skip("Hubs cannot be switched on and off")
|
|
|
|
if Module.LensMask in dev.modules:
|
|
state = dev.is_on
|
|
await dev.set_state(not state)
|
|
await dev.update()
|
|
assert dev.is_on is not state
|
|
|
|
dev.modules.pop(Module.LensMask) # type: ignore[attr-defined]
|
|
|
|
# Test with no lens mask module. Device is always on.
|
|
assert dev.is_on is True
|
|
res = await dev.set_state(False)
|
|
assert res == {}
|
|
await dev.update()
|
|
assert dev.is_on is True
|
|
|
|
|
|
@device_smartcam
|
|
async def test_alias(dev):
|
|
test_alias = "TEST1234"
|
|
original = dev.alias
|
|
|
|
assert isinstance(original, str)
|
|
await dev.set_alias(test_alias)
|
|
await dev.update()
|
|
assert dev.alias == test_alias
|
|
|
|
await dev.set_alias(original)
|
|
await dev.update()
|
|
assert dev.alias == original
|
|
|
|
|
|
@hub_smartcam
|
|
async def test_hub(dev):
|
|
assert dev.children
|
|
for child in dev.children:
|
|
assert "Cloud" in child.modules
|
|
assert child.modules["Cloud"].data
|
|
assert child.alias
|
|
await child.update()
|
|
assert "Time" not in child.modules
|
|
assert child.time
|
|
|
|
|
|
@device_smartcam
|
|
async def test_device_time(dev: Device, freezer: FrozenDateTimeFactory):
|
|
"""Test a child device gets the time from it's parent module."""
|
|
fallback_time = datetime.now(UTC).astimezone().replace(microsecond=0)
|
|
assert dev.time != fallback_time
|
|
module = dev.modules[Module.Time]
|
|
await module.set_time(fallback_time)
|
|
await dev.update()
|
|
assert dev.time == fallback_time
|