Remove experimental support (#1256)

This commit is contained in:
Steven B. 2024-11-14 14:55:02 +00:00 committed by GitHub
parent 6213b90f62
commit b8f6651d9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 5 additions and 100 deletions

View File

@ -309,10 +309,6 @@ async def cli(
if debug: if debug:
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
from kasa.experimental import Experimental
Experimental.set_enabled(True)
credentials = Credentials(username=username, password=password) credentials = Credentials(username=username, password=password)
if host is not None: if host is not None:
if discovery_info: if discovery_info:
@ -356,8 +352,7 @@ async def cli(
await handle_device(basedir, autosave, protocol, batch_size=batch_size) await handle_device(basedir, autosave, protocol, batch_size=batch_size)
else: else:
raise KasaException( raise KasaException(
"Could not find a protocol for the given parameters. " "Could not find a protocol for the given parameters."
+ "Maybe you need to enable --experimental."
) )
else: else:
click.echo("Host given, performing discovery on %s." % host) click.echo("Host given, performing discovery on %s." % host)

View File

@ -16,7 +16,6 @@ if TYPE_CHECKING:
from kasa import Device from kasa import Device
from kasa.deviceconfig import DeviceEncryptionType from kasa.deviceconfig import DeviceEncryptionType
from kasa.experimental import Experimental
from .common import ( from .common import (
SKIP_UPDATE_COMMANDS, SKIP_UPDATE_COMMANDS,
@ -220,14 +219,6 @@ def _legacy_type_to_class(_type: str) -> Any:
envvar="KASA_CREDENTIALS_HASH", envvar="KASA_CREDENTIALS_HASH",
help="Hashed credentials used to authenticate to the device.", help="Hashed credentials used to authenticate to the device.",
) )
@click.option(
"--experimental/--no-experimental",
default=None,
is_flag=True,
type=bool,
envvar=Experimental.ENV_VAR,
help="Enable experimental mode for devices not yet fully supported.",
)
@click.version_option(package_name="python-kasa") @click.version_option(package_name="python-kasa")
@click.pass_context @click.pass_context
async def cli( async def cli(
@ -249,7 +240,6 @@ async def cli(
username, username,
password, password,
credentials_hash, credentials_hash,
experimental,
): ):
"""A tool for controlling TP-Link smart home devices.""" # noqa """A tool for controlling TP-Link smart home devices.""" # noqa
# no need to perform any checks if we are just displaying the help # no need to perform any checks if we are just displaying the help
@ -261,12 +251,6 @@ async def cli(
if target != DEFAULT_TARGET and host: if target != DEFAULT_TARGET and host:
error("--target is not a valid option for single host discovery") error("--target is not a valid option for single host discovery")
if experimental is not None:
Experimental.set_enabled(experimental)
if Experimental.enabled():
echo("Experimental support is enabled")
logging_config: dict[str, Any] = { logging_config: dict[str, Any] = {
"level": logging.DEBUG if debug > 0 else logging.INFO "level": logging.DEBUG if debug > 0 else logging.INFO
} }
@ -332,10 +316,6 @@ async def cli(
dev = _legacy_type_to_class(type)(host, config=config) dev = _legacy_type_to_class(type)(host, config=config)
elif type in {"smart", "camera"} or (device_family and encrypt_type): elif type in {"smart", "camera"} or (device_family and encrypt_type):
if type == "camera": if type == "camera":
if not experimental:
error(
"Camera is an experimental type, please enable with --experimental"
)
encrypt_type = "AES" encrypt_type = "AES"
https = True https = True
device_family = "SMART.IPCAMERA" device_family = "SMART.IPCAMERA"

View File

@ -129,7 +129,6 @@ from kasa.exceptions import (
TimeoutError, TimeoutError,
UnsupportedDeviceError, UnsupportedDeviceError,
) )
from kasa.experimental import Experimental
from kasa.iot.iotdevice import IotDevice from kasa.iot.iotdevice import IotDevice
from kasa.json import DataClassJSONMixin from kasa.json import DataClassJSONMixin
from kasa.json import dumps as json_dumps from kasa.json import dumps as json_dumps
@ -589,9 +588,8 @@ class Discover:
main_device_families = { main_device_families = {
Device.Family.SmartTapoPlug, Device.Family.SmartTapoPlug,
Device.Family.IotSmartPlugSwitch, Device.Family.IotSmartPlugSwitch,
Device.Family.SmartIpCamera,
} }
if Experimental.enabled():
main_device_families.add(Device.Family.SmartIpCamera)
candidates: dict[ candidates: dict[
tuple[type[BaseProtocol], type[BaseTransport], type[Device]], tuple[type[BaseProtocol], type[BaseTransport], type[Device]],
tuple[BaseProtocol, DeviceConfig], tuple[BaseProtocol, DeviceConfig],

View File

@ -1,28 +0,0 @@
"""Package for experimental."""
from __future__ import annotations
import os
class Experimental:
"""Class for enabling experimental functionality."""
_enabled: bool | None = None
ENV_VAR = "KASA_EXPERIMENTAL"
@classmethod
def set_enabled(cls, enabled: bool) -> None:
"""Set the enabled value."""
cls._enabled = enabled
@classmethod
def enabled(cls) -> bool:
"""Get the enabled value."""
if cls._enabled is not None:
return cls._enabled
if env_var := os.getenv(cls.ENV_VAR):
return env_var.lower() in {"true", "1", "t", "on"}
return False

View File

@ -84,9 +84,6 @@ include = [
[tool.coverage.run] [tool.coverage.run]
source = ["kasa"] source = ["kasa"]
branch = true branch = true
omit = [
"kasa/experimental/*"
]
[tool.coverage.report] [tool.coverage.report]
exclude_lines = [ exclude_lines = [

View File

@ -861,9 +861,6 @@ async def test_host_auth_failed(discovery_mock, mocker, runner):
@pytest.mark.parametrize("device_type", TYPES) @pytest.mark.parametrize("device_type", TYPES)
async def test_type_param(device_type, mocker, runner): async def test_type_param(device_type, mocker, runner):
"""Test for handling only one of username or password supplied.""" """Test for handling only one of username or password supplied."""
if device_type == "camera":
pytest.skip(reason="camera is experimental")
result_device = FileNotFoundError result_device = FileNotFoundError
pass_dev = click.make_pass_decorator(Device) pass_dev = click.make_pass_decorator(Device)
@ -873,7 +870,9 @@ async def test_type_param(device_type, mocker, runner):
result_device = dev result_device = dev
mocker.patch("kasa.cli.device.state", new=_state) mocker.patch("kasa.cli.device.state", new=_state)
if device_type == "smart": if device_type == "camera":
expected_type = SmartCamera
elif device_type == "smart":
expected_type = SmartDevice expected_type = SmartDevice
else: else:
expected_type = _legacy_type_to_class(device_type) expected_type = _legacy_type_to_class(device_type)
@ -1253,39 +1252,3 @@ async def test_discover_config_invalid(mocker, runner):
) )
assert res.exit_code == 1 assert res.exit_code == 1
assert "--target is not a valid option for single host discovery" in res.output assert "--target is not a valid option for single host discovery" in res.output
@pytest.mark.parametrize(
("option", "env_var_value", "expectation"),
[
pytest.param("--experimental", None, True),
pytest.param("--experimental", "false", True),
pytest.param(None, None, False),
pytest.param(None, "true", True),
pytest.param(None, "false", False),
pytest.param("--no-experimental", "true", False),
],
)
async def test_experimental_flags(mocker, option, env_var_value, expectation):
"""Test the experimental flag is set correctly."""
mocker.patch("kasa.discover.Discover.try_connect_all", return_value=None)
# reset the class internal variable
from kasa.experimental import Experimental
Experimental._enabled = None
KASA_VARS = {k: None for k, v in os.environ.items() if k.startswith("KASA_")}
if env_var_value:
KASA_VARS["KASA_EXPERIMENTAL"] = env_var_value
args = [
"--host",
"127.0.0.2",
"discover",
"config",
]
if option:
args.insert(0, option)
runner = CliRunner(env=KASA_VARS)
res = await runner.invoke(cli, args)
assert ("Experimental support is enabled" in res.output) is expectation