Add common alarm interface (#1479)
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

Add a common interface for the `alarm` module across `smart` and `smartcam` devices.
This commit is contained in:
Steven B.
2025-01-26 13:33:13 +00:00
committed by GitHub
parent d857cc68bb
commit 656c88771a
7 changed files with 161 additions and 30 deletions

View File

@@ -276,12 +276,14 @@ class FakeSmartCamTransport(BaseTransport):
section = next(iter(val))
skey_val = val[section]
if not isinstance(skey_val, dict): # single level query
section_key = section
section_val = skey_val
if (get_info := info.get(get_method)) and section_key in get_info:
get_info[section_key] = section_val
else:
updates = {
k: v for k, v in val.items() if k in info.get(get_method, {})
}
if len(updates) != len(val):
# All keys to update must already be in the getter
return {"error_code": -1}
info[get_method] = {**info[get_method], **updates}
break
for skey, sval in skey_val.items():
section_key = skey

View File

@@ -4,14 +4,13 @@ from __future__ import annotations
import pytest
from kasa import Device
from kasa import Device, Module
from kasa.smartcam.modules.alarm import (
DURATION_MAX,
DURATION_MIN,
VOLUME_MAX,
VOLUME_MIN,
)
from kasa.smartcam.smartcammodule import SmartCamModule
from ...conftest import hub_smartcam
@@ -19,7 +18,7 @@ from ...conftest import hub_smartcam
@hub_smartcam
async def test_alarm(dev: Device):
"""Test device alarm."""
alarm = dev.modules.get(SmartCamModule.SmartCamAlarm)
alarm = dev.modules.get(Module.Alarm)
assert alarm
original_duration = alarm.alarm_duration
@@ -63,6 +62,19 @@ async def test_alarm(dev: Device):
await dev.update()
assert alarm.alarm_sound == new_sound
# Test play parameters
await alarm.play(
duration=original_duration, volume=original_volume, sound=original_sound
)
await dev.update()
assert alarm.active
assert alarm.alarm_sound == original_sound
assert alarm.alarm_duration == original_duration
assert alarm.alarm_volume == original_volume
await alarm.stop()
await dev.update()
assert not alarm.active
finally:
await alarm.set_alarm_volume(original_volume)
await alarm.set_alarm_duration(original_duration)
@@ -73,7 +85,7 @@ async def test_alarm(dev: Device):
@hub_smartcam
async def test_alarm_invalid_setters(dev: Device):
"""Test device alarm invalid setter values."""
alarm = dev.modules.get(SmartCamModule.SmartCamAlarm)
alarm = dev.modules.get(Module.Alarm)
assert alarm
# test set sound invalid
@@ -95,7 +107,7 @@ async def test_alarm_invalid_setters(dev: Device):
@hub_smartcam
async def test_alarm_features(dev: Device):
"""Test device alarm features."""
alarm = dev.modules.get(SmartCamModule.SmartCamAlarm)
alarm = dev.modules.get(Module.Alarm)
assert alarm
original_duration = alarm.alarm_duration