2019-11-11 21:14:34 +00:00
|
|
|
"""Python interface for TP-Link's smart home devices.
|
2017-05-26 14:11:03 +00:00
|
|
|
|
|
|
|
All common, shared functionalities are available through `SmartDevice` class::
|
|
|
|
|
|
|
|
x = SmartDevice("192.168.1.1")
|
|
|
|
print(x.sys_info)
|
|
|
|
|
2019-11-11 21:14:34 +00:00
|
|
|
For device type specific actions `SmartBulb`, `SmartPlug`, or `SmartStrip`
|
|
|
|
should be used instead.
|
2017-05-26 14:11:03 +00:00
|
|
|
|
|
|
|
Module-specific errors are raised as `SmartDeviceException` and are expected
|
|
|
|
to be handled by the user of the library.
|
|
|
|
"""
|
2023-05-17 18:33:02 +00:00
|
|
|
from importlib.metadata import version
|
2024-02-04 15:20:08 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2024-01-26 09:11:31 +00:00
|
|
|
from warnings import warn
|
2021-03-18 18:22:10 +00:00
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa.bulb import Bulb
|
2023-09-13 13:46:38 +00:00
|
|
|
from kasa.credentials import Credentials
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa.device import Device
|
|
|
|
from kasa.device_type import DeviceType
|
2023-12-29 19:17:15 +00:00
|
|
|
from kasa.deviceconfig import (
|
|
|
|
ConnectionType,
|
|
|
|
DeviceConfig,
|
|
|
|
DeviceFamilyType,
|
|
|
|
EncryptType,
|
|
|
|
)
|
2019-12-18 08:11:18 +00:00
|
|
|
from kasa.discover import Discover
|
2021-09-23 15:58:19 +00:00
|
|
|
from kasa.emeterstatus import EmeterStatus
|
2023-09-13 13:46:38 +00:00
|
|
|
from kasa.exceptions import (
|
|
|
|
AuthenticationException,
|
|
|
|
SmartDeviceException,
|
2024-01-11 15:13:44 +00:00
|
|
|
TimeoutException,
|
2023-09-13 13:46:38 +00:00
|
|
|
UnsupportedDeviceException,
|
|
|
|
)
|
2024-02-15 15:25:08 +00:00
|
|
|
from kasa.feature import Feature, FeatureType
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa.iot.iotbulb import BulbPreset, TurnOnBehavior, TurnOnBehaviors
|
2024-01-26 09:11:31 +00:00
|
|
|
from kasa.iotprotocol import (
|
|
|
|
IotProtocol,
|
|
|
|
_deprecated_TPLinkSmartHomeProtocol, # noqa: F401
|
|
|
|
)
|
2024-02-04 15:20:08 +00:00
|
|
|
from kasa.plug import Plug
|
2024-01-26 09:11:31 +00:00
|
|
|
from kasa.protocol import BaseProtocol
|
2023-12-04 18:50:05 +00:00
|
|
|
from kasa.smartprotocol import SmartProtocol
|
2019-11-11 18:26:06 +00:00
|
|
|
|
2020-05-12 10:11:47 +00:00
|
|
|
__version__ = version("python-kasa")
|
|
|
|
|
|
|
|
|
2019-11-11 18:26:06 +00:00
|
|
|
__all__ = [
|
|
|
|
"Discover",
|
2024-01-22 15:28:30 +00:00
|
|
|
"BaseProtocol",
|
2023-12-04 18:50:05 +00:00
|
|
|
"IotProtocol",
|
|
|
|
"SmartProtocol",
|
2024-02-04 15:20:08 +00:00
|
|
|
"BulbPreset",
|
2022-10-27 15:40:54 +00:00
|
|
|
"TurnOnBehaviors",
|
|
|
|
"TurnOnBehavior",
|
2019-11-11 18:26:06 +00:00
|
|
|
"DeviceType",
|
2024-02-15 15:25:08 +00:00
|
|
|
"Feature",
|
|
|
|
"FeatureType",
|
2019-11-11 18:26:06 +00:00
|
|
|
"EmeterStatus",
|
2024-02-04 15:20:08 +00:00
|
|
|
"Device",
|
|
|
|
"Bulb",
|
|
|
|
"Plug",
|
2019-11-11 18:26:06 +00:00
|
|
|
"SmartDeviceException",
|
2023-09-13 13:46:38 +00:00
|
|
|
"AuthenticationException",
|
|
|
|
"UnsupportedDeviceException",
|
2024-01-11 15:13:44 +00:00
|
|
|
"TimeoutException",
|
2023-09-13 13:46:38 +00:00
|
|
|
"Credentials",
|
2023-12-29 19:17:15 +00:00
|
|
|
"DeviceConfig",
|
|
|
|
"ConnectionType",
|
|
|
|
"EncryptType",
|
|
|
|
"DeviceFamilyType",
|
2019-11-11 18:26:06 +00:00
|
|
|
]
|
2024-01-26 09:11:31 +00:00
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from . import iot
|
|
|
|
|
2024-01-26 09:11:31 +00:00
|
|
|
deprecated_names = ["TPLinkSmartHomeProtocol"]
|
2024-02-04 15:20:08 +00:00
|
|
|
deprecated_smart_devices = {
|
|
|
|
"SmartDevice": iot.IotDevice,
|
|
|
|
"SmartPlug": iot.IotPlug,
|
|
|
|
"SmartBulb": iot.IotBulb,
|
|
|
|
"SmartLightStrip": iot.IotLightStrip,
|
|
|
|
"SmartStrip": iot.IotStrip,
|
|
|
|
"SmartDimmer": iot.IotDimmer,
|
|
|
|
"SmartBulbPreset": BulbPreset,
|
|
|
|
}
|
2024-01-26 09:11:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def __getattr__(name):
|
|
|
|
if name in deprecated_names:
|
|
|
|
warn(f"{name} is deprecated", DeprecationWarning, stacklevel=1)
|
|
|
|
return globals()[f"_deprecated_{name}"]
|
2024-02-04 15:20:08 +00:00
|
|
|
if name in deprecated_smart_devices:
|
|
|
|
new_class = deprecated_smart_devices[name]
|
|
|
|
package_name = ".".join(new_class.__module__.split(".")[:-1])
|
|
|
|
warn(
|
|
|
|
f"{name} is deprecated, use {new_class.__name__} "
|
|
|
|
+ f"from package {package_name} instead or use Discover.discover_single()"
|
|
|
|
+ " and Device.connect() to support new protocols",
|
|
|
|
DeprecationWarning,
|
|
|
|
stacklevel=1,
|
|
|
|
)
|
|
|
|
return new_class
|
2024-01-26 09:11:31 +00:00
|
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
2024-02-04 15:20:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
SmartDevice = Device
|
|
|
|
SmartBulb = iot.IotBulb
|
|
|
|
SmartPlug = iot.IotPlug
|
|
|
|
SmartLightStrip = iot.IotLightStrip
|
|
|
|
SmartStrip = iot.IotStrip
|
|
|
|
SmartDimmer = iot.IotDimmer
|
|
|
|
SmartBulbPreset = BulbPreset
|
|
|
|
# Instanstiate all classes so the type checkers catch abstract issues
|
|
|
|
from . import smart
|
|
|
|
|
|
|
|
smart.SmartDevice("127.0.0.1")
|
|
|
|
smart.SmartPlug("127.0.0.1")
|
|
|
|
smart.SmartBulb("127.0.0.1")
|
|
|
|
iot.IotDevice("127.0.0.1")
|
|
|
|
iot.IotPlug("127.0.0.1")
|
|
|
|
iot.IotBulb("127.0.0.1")
|
|
|
|
iot.IotLightStrip("127.0.0.1")
|
|
|
|
iot.IotStrip("127.0.0.1")
|
|
|
|
iot.IotDimmer("127.0.0.1")
|