mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Refactor devices into subpackages and deprecate old names (#716)
* Refactor devices into subpackages and deprecate old names * Tweak and add tests * Fix linting * Remove duplicate implementations affecting project coverage * Update post review * Add device base class attributes and rename subclasses * Rename Module to BaseModule * Remove has_emeter_history * Fix missing _time in init * Update post review * Fix test_readmeexamples * Fix erroneously duped files * Clean up iot and smart imports * Update post latest review * Tweak Device docstring
This commit is contained in:
@@ -6,15 +6,17 @@ This script can be used to create fixture files for individual modules.
|
||||
import asyncio
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import cast
|
||||
|
||||
import typer
|
||||
|
||||
from kasa import Discover, SmartDevice
|
||||
from kasa import Discover
|
||||
from kasa.iot import IotDevice
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
def create_fixtures(dev: SmartDevice, outputdir: Path):
|
||||
def create_fixtures(dev: IotDevice, outputdir: Path):
|
||||
"""Iterate over supported modules and create version-specific fixture files."""
|
||||
for name, module in dev.modules.items():
|
||||
module_dir = outputdir / name
|
||||
@@ -43,13 +45,14 @@ def create_module_fixtures(
|
||||
"""Create module fixtures for given host/network."""
|
||||
devs = []
|
||||
if host is not None:
|
||||
dev: SmartDevice = asyncio.run(Discover.discover_single(host))
|
||||
dev: IotDevice = cast(IotDevice, asyncio.run(Discover.discover_single(host)))
|
||||
devs.append(dev)
|
||||
else:
|
||||
if network is None:
|
||||
network = "255.255.255.255"
|
||||
devs = asyncio.run(Discover.discover(target=network)).values()
|
||||
for dev in devs:
|
||||
dev = cast(IotDevice, dev)
|
||||
asyncio.run(dev.update())
|
||||
|
||||
for dev in devs:
|
||||
|
@@ -23,14 +23,14 @@ from devtools.helpers.smartrequests import COMPONENT_REQUESTS, SmartRequest
|
||||
from kasa import (
|
||||
AuthenticationException,
|
||||
Credentials,
|
||||
Device,
|
||||
Discover,
|
||||
SmartDevice,
|
||||
SmartDeviceException,
|
||||
TimeoutException,
|
||||
)
|
||||
from kasa.discover import DiscoveryResult
|
||||
from kasa.exceptions import SmartErrorCode
|
||||
from kasa.tapo.tapodevice import TapoDevice
|
||||
from kasa.smart import SmartDevice
|
||||
|
||||
Call = namedtuple("Call", "module method")
|
||||
SmartCall = namedtuple("SmartCall", "module request should_succeed")
|
||||
@@ -119,9 +119,9 @@ def default_to_regular(d):
|
||||
return d
|
||||
|
||||
|
||||
async def handle_device(basedir, autosave, device: SmartDevice, batch_size: int):
|
||||
async def handle_device(basedir, autosave, device: Device, batch_size: int):
|
||||
"""Create a fixture for a single device instance."""
|
||||
if isinstance(device, TapoDevice):
|
||||
if isinstance(device, SmartDevice):
|
||||
filename, copy_folder, final = await get_smart_fixture(device, batch_size)
|
||||
else:
|
||||
filename, copy_folder, final = await get_legacy_fixture(device)
|
||||
@@ -319,7 +319,7 @@ async def _make_requests_or_exit(
|
||||
exit(1)
|
||||
|
||||
|
||||
async def get_smart_fixture(device: TapoDevice, batch_size: int):
|
||||
async def get_smart_fixture(device: SmartDevice, batch_size: int):
|
||||
"""Get fixture for new TAPO style protocol."""
|
||||
extra_test_calls = [
|
||||
SmartCall(
|
||||
|
Reference in New Issue
Block a user