API Reference

Discover

class kasa.Discover[source]

Class for discovering devices.

async static discover(*, target: str = '255.255.255.255', on_discovered: Callable[[Device], Coroutine] | None = None, discovery_timeout: int = 5, discovery_packets: int = 3, interface: str | None = None, on_unsupported: Callable[[UnsupportedDeviceError], Coroutine] | None = None, credentials: Credentials | None = None, username: str | None = None, password: str | None = None, port: int | None = None, timeout: int | None = None) dict[str, Device][source]

Discover supported devices.

Sends discovery message to 255.255.255.255:9999 and 255.255.255.255:20002 in order to detect available supported devices in the local network, and waits for given timeout for answers from devices. If you have multiple interfaces, you can use target parameter to specify the network for discovery.

If given, on_discovered coroutine will get awaited with a Device-derived object as parameter.

The results of the discovery are returned as a dict of Device-derived objects keyed with IP addresses. The devices are already initialized and all but emeter-related properties can be accessed directly.

Parameters:
  • target – The target address where to send the broadcast discovery queries if multi-homing (e.g. 192.168.xxx.255).

  • on_discovered – coroutine to execute on discovery

  • discovery_timeout – Seconds to wait for responses, defaults to 5

  • discovery_packets – Number of discovery packets to broadcast

  • interface – Bind to specific interface

  • on_unsupported – Optional callback when unsupported devices are discovered

  • credentials – Credentials for devices that require authentication. username and password are ignored if provided.

  • username – Username for devices that require authentication

  • password – Password for devices that require authentication

  • port – Override the discovery port for devices listening on 9999

  • timeout – Query timeout in seconds for devices returned by discovery

Returns:

dictionary with discovered devices

async static discover_single(host: str, *, discovery_timeout: int = 5, port: int | None = None, timeout: int | None = None, credentials: Credentials | None = None, username: str | None = None, password: str | None = None, on_unsupported: Callable[[UnsupportedDeviceError], Coroutine] | None = None) Device | None[source]

Discover a single device by the given IP address.

It is generally preferred to avoid discover_single() and use Device.connect() instead as it should perform better when the WiFi network is congested or the device is not responding to discovery requests.

Parameters:
  • host – Hostname of device to query

  • discovery_timeout – Timeout in seconds for discovery

  • port – Optionally set a different port for legacy devices using port 9999

  • timeout – Timeout in seconds device for devices queries

  • credentials – Credentials for devices that require authentication. username and password are ignored if provided.

  • username – Username for devices that require authentication

  • password – Password for devices that require authentication

Return type:

SmartDevice

Returns:

Object for querying/controlling found device.

async static try_connect_all(host: str, *, port: int | None = None, timeout: int | None = None, credentials: Credentials | None = None, http_client: ClientSession | None = None, on_attempt: Callable[[ConnectAttempt, bool], None] | None = None) Device | None[source]

Try to connect directly to a device with all possible parameters.

This method can be used when udp is not working due to network issues. After succesfully connecting use the device config and Device.connect() for future connections.

Parameters:
  • host – Hostname of device to query

  • port – Optionally set a different port for legacy devices using port 9999

  • timeout – Timeout in seconds device for devices queries

  • credentials – Credentials for devices that require authentication.

  • http_client – Optional client session for devices that use http. username and password are ignored if provided.

Device

class kasa.Device(host: str, *, config: DeviceConfig | None = None, protocol: BaseProtocol | None = None)[source]

Common device interface.

Do not instantiate this class directly, instead get a device instance from Device.connect(), Discover.discover() or Discover.discover_single().

Config

alias of DeviceConfig

ConnectionParameters

alias of DeviceConnectionParameters

class Credentials(username: str = '', password: str = '')

Credentials for authentication.

password: str = ''

Password of the cloud account

username: str = ''

Username (email address) of the cloud account

EncryptionType

alias of DeviceEncryptionType

Family

alias of DeviceFamily

Type

alias of DeviceType

abstract property alias: str | None

Returns the device alias or nickname.

property children: Sequence[Device]

Returns the child devices.

property config: DeviceConfig

Return the device configuration.

async static connect(*, host: str | None = None, config: DeviceConfig | None = None) Device[source]

Connect to a single device by the given hostname or device configuration.

This method avoids the UDP based discovery process and will connect directly to the device.

It is generally preferred to avoid discover_single() and use this function instead as it should perform better when the WiFi network is congested or the device is not responding to discovery requests.

Parameters:
  • host – Hostname of device to query

  • config – Connection parameters to ensure the correct protocol and connection options are used.

Return type:

SmartDevice

Returns:

Object for querying/controlling found device.

property credentials: Credentials | None

The device credentials.

property credentials_hash: str | None

The protocol specific hash of the credentials the device is using.

abstract property device_id: str

Return the device id.

property device_type: DeviceType

Return the device type.

async disconnect() None[source]

Disconnect and close any underlying connection resources.

abstract async factory_reset() None[source]

Reset device back to factory settings.

Note, this does not downgrade the firmware.

property features: dict[str, Feature]

Return the list of supported features.

get_child_device(name_or_id: str) Device | None[source]

Return child device by its device_id or alias.

get_plug_by_index(index: int) Device[source]

Return child device for the given index.

get_plug_by_name(name: str) Device[source]

Return child device for the given name.

abstract property has_emeter: bool

Return if the device has emeter.

property host: str

The device host.

abstract property hw_info: dict

Return hardware info for the device.

abstract property internal_state: dict

Return all the internal state data.

property is_off: bool

Return True if device is off.

abstract property is_on: bool

Return true if the device is on.

abstract property location: dict

Return the device location.

abstract property mac: str

Return the mac formatted with colons.

abstract property model: str

Returns the device model.

abstract property modules: ModuleMapping[Module]

Return the device modules.

abstract property on_since: datetime | None

Return the time that the device was turned on or None if turned off.

This returns a cached value if the device reported value difference is under five seconds to avoid device-caused jitter.

property parent: Device | None

Return the parent on child devices.

property port: int

The device port.

abstract async reboot(delay: int = 1) None[source]

Reboot the device.

Note that giving a delay of zero causes this to block, as the device reboots immediately without responding to the call.

abstract property rssi: int | None

Return the rssi.

abstract async set_alias(alias: str) dict[source]

Set the device name (alias).

abstract async set_state(on: bool) dict[source]

Set the device state to on.

This allows turning the device on and off. See also turn_off and turn_on.

property state_information: dict[str, Any]

Return available features and their values.

abstract property sys_info: dict[str, Any]

Returns the device info.

abstract property time: datetime

Return the time.

abstract property timezone: tzinfo

Return the timezone and time_difference.

abstract async turn_off(**kwargs) dict[source]

Turn off the device.

abstract async turn_on(**kwargs) dict[source]

Turn on the device.

abstract async update(update_children: bool = True) None[source]

Update the device.

abstract update_from_discover_info(info: dict) None[source]

Update state from info from the discover call.

abstract async wifi_join(ssid: str, password: str, keytype: str = 'wpa2_psk') dict[source]

Join the given wifi network.

abstract async wifi_scan() list[WifiNetwork][source]

Scan for available wifi networks.

Device Config

class kasa.Credentials(username: str = '', password: str = '')[source]

Credentials for authentication.

password: str = ''

Password of the cloud account

username: str = ''

Username (email address) of the cloud account

class kasa.DeviceConfig(host: str, timeout: int | None = 5, port_override: int | None = None, credentials: ~kasa.credentials.Credentials | None = None, credentials_hash: str | None = None, batch_size: int | None = None, connection_type: ~kasa.deviceconfig.DeviceConnectionParameters = <factory>, uses_http: bool = False, http_client: ~aiohttp.client.ClientSession | None = None, aes_keys: ~kasa.deviceconfig.KeyPairDict | None = None)[source]

Class to represent paramaters that determine how to connect to devices.

DEFAULT_TIMEOUT = 5
aes_keys: KeyPairDict | None = None
batch_size: int | None = None

The protocol specific type of connection. Defaults to the legacy type.

connection_type: DeviceConnectionParameters

The batch size for protoools supporting multiple request batches.

credentials: Credentials | None = None

Credentials for devices requiring authentication

credentials_hash: str | None = None

Credentials hash for devices requiring authentication. If credentials are also supplied they take precendence over credentials_hash. Credentials hash can be retrieved from Device.credentials_hash

classmethod from_dict(d, *, dialect=None)
host: str

IP address or hostname

http_client: ClientSession | None = None

Set a custom http_client for the device to use.

port_override: int | None = None

Override the default 9999 port to support port forwarding

timeout: int | None = 5

Timeout for querying the device

to_dict()
to_dict_control_credentials(*, credentials_hash: str | None = None, exclude_credentials: bool = False) dict[str, dict[str, str]][source]

Convert deviceconfig to dict controlling how to serialize credentials.

If credentials_hash is provided credentials will be None. If credentials_hash is ‘’ credentials_hash and credentials will be None. exclude credentials controls whether to include credentials. The defaults are the same as calling to_dict().

uses_http: bool = False

True if the device uses http. Consumers should retrieve rather than set this in order to determine whether they should pass a custom http client if desired.

class kasa.DeviceFamily(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Encrypt type enum.

IotSmartBulb = 'IOT.SMARTBULB'
IotSmartPlugSwitch = 'IOT.SMARTPLUGSWITCH'
SmartIpCamera = 'SMART.IPCAMERA'
SmartKasaHub = 'SMART.KASAHUB'
SmartKasaPlug = 'SMART.KASAPLUG'
SmartKasaSwitch = 'SMART.KASASWITCH'
SmartTapoBulb = 'SMART.TAPOBULB'
SmartTapoHub = 'SMART.TAPOHUB'
SmartTapoPlug = 'SMART.TAPOPLUG'
SmartTapoSwitch = 'SMART.TAPOSWITCH'
class kasa.DeviceConnectionParameters(device_family: DeviceFamily, encryption_type: DeviceEncryptionType, login_version: int | None = None, https: bool = False)[source]

Class to hold the the parameters determining connection type.

device_family: DeviceFamily
encryption_type: DeviceEncryptionType
classmethod from_dict(d, *, dialect=None)
static from_values(device_family: str, encryption_type: str, login_version: int | None = None, https: bool | None = None) DeviceConnectionParameters[source]

Return connection parameters from string values.

https: bool = False
login_version: int | None = None
to_dict()
class kasa.DeviceEncryptionType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Encrypt type enum.

Aes = 'AES'
Klap = 'KLAP'
Xor = 'XOR'

Modules and Features

class kasa.Module(device: Device, module: str)[source]

Base class implemention for all modules.

The base classes should implement query to return the query they want to be executed during the regular update cycle.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None[source]

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool[source]

Return True if the module attribute feature is supported.

abstract query() dict[source]

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

class kasa.Feature(device: Device, id: str, name: str, type: Feature.Type, attribute_getter: str | Callable | None = None, attribute_setter: str | Callable[..., Coroutine[Any, Any, Any]] | None = None, container: Any = None, icon: str | None = None, unit_getter: str | Callable[[], str] | None = None, category: Feature.Category = Category.Unset, precision_hint: int | None = None, range_getter: str | Callable[[], tuple[int, int]] | None = None, choices_getter: str | Callable[[], list[str]] | None = None)[source]

Feature defines a generic interface for device features.

Action = 4
BinarySensor = 2
class Category(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Category hint to allow feature grouping.

Config = 2

Config features change device behavior without immediate state changes.

Debug = 4

Debug features deliver more verbose information then informative features. You may want to hide these per default to avoid cluttering your UI.

Info = 3

Informative/sensor features deliver some potentially interesting information.

Primary = 1

Primary features control the device state directly. Examples include turning the device on/off, or adjusting its brightness.

Unset = -1

The default category if none is specified.

Choice = 6
DEFAULT_MAX = 65536
Number = 5
Sensor = 1
Switch = 3
class Type(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Type to help decide how to present the feature.

Action = 4

Action triggers some action on device

BinarySensor = 2

BinarySensor is a read-only boolean

Choice = 6

Choice defines a setting with pre-defined values

Number = 5

Number defines a numeric setting See range_getter, Feature.minimum_value, and maximum_value

Sensor = 1

Sensor is an informative read-only value

Switch = 3

Switch is a boolean setting

Unknown = -1
attribute_getter: str | Callable | None = None

Callable or name of the property that allows accessing the value

attribute_setter: str | Callable[..., Coroutine[Any, Any, Any]] | None = None

Callable coroutine or name of the method that allows changing the value

category: Feature.Category = -1

Category hint for downstreams

property choices: list[str] | None

List of choices.

choices_getter: str | Callable[[], list[str]] | None = None

Attribute name of the choices getter property. If set, this property will be used to get choices.

container: Any = None

Container storing the data, this overrides ‘device’ for getters

device: Device

Device instance required for getting and setting values

icon: str | None = None

Icon suggestion

id: str

Identifier

property maximum_value: int

Maximum value.

property minimum_value: int

Minimum value.

name: str

User-friendly short description

precision_hint: int | None = None

Hint to help rounding the sensor values to given after-comma digits

property range: tuple[int, int] | None[source]

Range of values if applicable.

range_getter: str | Callable[[], tuple[int, int]] | None = None

Attribute containing the name of the range getter property. If set, this property will be used to set minimum_value and maximum_value.

async set_value(value: int | float | bool | str | Enum | None) Any[source]

Set the value.

type: Feature.Type

Type of the feature

property unit: str | None

Unit if applicable.

unit_getter: str | Callable[[], str] | None = None

Attribute containing the name of the unit getter property. If set, this property will be used to get the unit.

property value: int | float | bool | str | Enum | None

Return the current value.

Package for interfaces.

class kasa.interfaces.Energy(device: Device, module: str)[source]

Base interface to represent an Energy module.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
class ModuleFeature(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Features supported by the device.

CONSUMPTION_TOTAL = 2

Device reports consumption_total

PERIODIC_STATS = 4

Device reports periodic stats via get_daily_stats() and get_monthly_stats()

VOLTAGE_CURRENT = 1

Device reports voltage and current

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

denominator

the denominator of a rational number in lowest terms

from_bytes(byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

imag

the imaginary part of a complex number

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property consumption_this_month: float | None

Return this month’s energy consumption in kWh.

abstract property consumption_today: float | None

Return today’s energy consumption in kWh.

abstract property consumption_total: float | None

Return total consumption since last reboot in kWh.

abstract property current: float | None

Return the current in A.

abstract property current_consumption: float | None

Get the current power consumption in Watt.

abstract property data: dict

Return the module specific raw data from the last update.

abstract async erase_stats() dict[source]

Erase all stats.

abstract async get_daily_stats(*, year: int | None = None, month: int | None = None, kwh: bool = True) dict[source]

Return daily stats for the given year & month.

The return value is a dictionary of {day: energy, …}.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

abstract async get_monthly_stats(*, year: int | None = None, kwh: bool = True) dict[source]

Return monthly stats for the given year.

abstract async get_status() EmeterStatus[source]

Return real-time statistics.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract property status: EmeterStatus

Return current energy readings.

supports(module_feature: ModuleFeature) bool[source]

Return True if module supports the feature.

abstract property voltage: float | None

Get the current voltage in V.

class kasa.interfaces.Fan(device: Device, module: str)[source]

Interface for a Fan.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

abstract property fan_speed_level: Annotated[int, FeatureAttribute]

Return fan speed level.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_fan_speed_level(level: int) Annotated[dict, FeatureAttribute][source]

Set fan speed level.

class kasa.interfaces.Led(device: Device, module: str)[source]

Base interface to represent a LED module.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract property led: bool

Return current led status.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_led(enable: bool) dict[source]

Set led.

class kasa.interfaces.Light(device: Device, module: str)[source]

Base class for TP-Link Light.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property brightness: Annotated[int, FeatureAttribute]

Return the current brightness in percentage.

abstract property color_temp: Annotated[int, FeatureAttribute]

Whether the bulb supports color temperature changes.

abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

abstract property has_effects: bool

Return True if the device supports effects.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract property hsv: Annotated[HSV, FeatureAttribute]

Return the current HSV state of the bulb.

Returns:

hue, saturation and value (degrees, %, %)

abstract property is_color: bool

Whether the bulb supports color changes.

abstract property is_dimmable: bool

Whether the light supports brightness changes.

abstract property is_variable_color_temp: bool

Whether the bulb supports color temperature changes.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_brightness(brightness: int, *, transition: int | None = None) Annotated[dict, FeatureAttribute][source]

Set the brightness in percentage.

Note, transition is not supported and will be ignored.

Parameters:
  • brightness (int) – brightness in percent

  • transition (int) – transition in milliseconds.

abstract async set_color_temp(temp: int, *, brightness: int | None = None, transition: int | None = None) Annotated[dict, FeatureAttribute][source]

Set the color temperature of the device in kelvin.

Note, transition is not supported and will be ignored.

Parameters:
  • temp (int) – The new color temperature, in Kelvin

  • transition (int) – transition in milliseconds.

abstract async set_hsv(hue: int, saturation: int, value: int | None = None, *, transition: int | None = None) Annotated[dict, FeatureAttribute][source]

Set new HSV.

Note, transition is not supported and will be ignored.

Parameters:
  • hue (int) – hue in degrees

  • saturation (int) – saturation in percentage [0,100]

  • value (int) – value in percentage [0, 100]

  • transition (int) – transition in milliseconds.

abstract async set_state(state: LightState) dict[source]

Set the light state.

abstract property state: LightState

Return the current light state.

abstract property valid_temperature_range: ColorTempRange

Return the device-specific white temperature range (in Kelvin).

Returns:

White temperature range in Kelvin (minimum, maximum)

class kasa.interfaces.LightEffect(device: Device, module: str)[source]

Interface to represent a light effect module.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
LIGHT_EFFECTS_OFF = 'Off'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

abstract property effect: str

Return effect state or name.

abstract property effect_list: list[str]

Return built-in effects list.

Example:

[‘Aurora’, ‘Bubbling Cauldron’, …]

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

abstract property has_custom_effects: bool

Return True if the device supports setting custom effects.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_custom_effect(effect_dict: dict) dict[source]

Set a custom effect on the device.

Parameters:

effect_dict (str) – The custom effect dict to set

abstract async set_effect(effect: str, *, brightness: int | None = None, transition: int | None = None) dict[source]

Set an effect on the device.

If brightness or transition is defined, its value will be used instead of the effect-specific default.

See effect_list() for available effects, or use set_custom_effect() for custom effects.

Parameters:
  • effect (str) – The effect to set

  • brightness (int) – The wanted brightness

  • transition (int) – The wanted transition time

class kasa.interfaces.LightPreset(device: Device, module: str)[source]

Base interface for light preset module.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
PRESET_NOT_SET = 'Not set'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract property has_save_preset: bool

Return True if the device supports updating presets.

abstract property preset: str

Return current preset name.

abstract property preset_list: list[str]

Return list of preset names.

Example:

[‘Off’, ‘Preset 1’, ‘Preset 2’, …]

abstract property preset_states_list: Sequence[LightState]

Return list of preset states.

Example:

[‘Off’, ‘Preset 1’, ‘Preset 2’, …]

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async save_preset(preset_name: str, preset_info: LightState) dict[source]

Update the preset with preset_name with the new preset_info.

abstract async set_preset(preset_name: str) dict[source]

Set a light preset for the device.

class kasa.interfaces.LightState(light_on: bool | None = None, brightness: int | None = None, hue: int | None = None, saturation: int | None = None, color_temp: int | None = None, transition: int | None = None)[source]

Class for smart light preset info.

brightness: int | None = None
color_temp: int | None = None
hue: int | None = None
light_on: bool | None = None
saturation: int | None = None
transition: int | None = None
class kasa.interfaces.Thermostat(device: Device, module: str)[source]

Base class for TP-Link Thermostat.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract property mode: ThermostatState

Return thermostat state.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_state(enabled: bool) dict[source]

Set thermostat state.

abstract async set_target_temperature(target: float) Annotated[dict, FeatureAttribute][source]

Set target temperature.

abstract async set_temperature_unit(unit: Literal['celsius', 'fahrenheit']) dict[source]

Set the device temperature unit.

abstract property state: bool

Return thermostat state.

abstract property target_temperature: Annotated[float, FeatureAttribute]

Return target temperature.

abstract property temperature: Annotated[float, FeatureAttribute]

Return current humidity in percentage.

abstract property temperature_unit: Literal['celsius', 'fahrenheit']

Return current temperature unit.

class kasa.interfaces.ThermostatState(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Thermostat state.

Calibrating = 'progress_calibration'
Heating = 'heating'
Idle = 'idle'
Off = 'off'
Unknown = 'unknown'
class kasa.interfaces.Time(device: Device, module: str)[source]

Base class for tplink time module.

Alarm: Final[ModuleName[smart.Alarm]] = 'Alarm'
AutoOff: Final[ModuleName[smart.AutoOff]] = 'AutoOff'
BatterySensor: Final[ModuleName[smart.BatterySensor]] = 'BatterySensor'
Brightness: Final[ModuleName[smart.Brightness]] = 'Brightness'
Camera: Final[ModuleName[smartcam.Camera]] = 'Camera'
ChildDevice: Final[ModuleName[smart.ChildDevice]] = 'ChildDevice'
ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
Color: Final[ModuleName[smart.Color]] = 'Color'
ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
HumiditySensor: Final[ModuleName[smart.HumiditySensor]] = 'HumiditySensor'
IotAmbientLight: Final[ModuleName[iot.AmbientLight]] = 'ambient'
IotAntitheft: Final[ModuleName[iot.Antitheft]] = 'anti_theft'
IotCloud: Final[ModuleName[iot.Cloud]] = 'cloud'
IotCountdown: Final[ModuleName[iot.Countdown]] = 'countdown'
IotLightEffect: Final[ModuleName[iot.LightEffect]] = 'LightEffect'
IotMotion: Final[ModuleName[iot.Motion]] = 'motion'
IotSchedule: Final[ModuleName[iot.Schedule]] = 'schedule'
IotUsage: Final[ModuleName[iot.Usage]] = 'usage'
Led: Final[ModuleName[interfaces.Led]] = 'Led'
Light: Final[ModuleName[interfaces.Light]] = 'Light'
LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
TemperatureControl: Final[ModuleName[smart.TemperatureControl]] = 'TemperatureControl'
TemperatureSensor: Final[ModuleName[smart.TemperatureSensor]] = 'TemperatureSensor'
Thermostat: Final[ModuleName[interfaces.Thermostat]] = 'Thermostat'
Time: Final[ModuleName[interfaces.Time]] = 'Time'
TriggerLogs: Final[ModuleName[smart.TriggerLogs]] = 'TriggerLogs'
WaterleakSensor: Final[ModuleName[smart.WaterleakSensor]] = 'WaterleakSensor'
abstract property data: dict

Return the module specific raw data from the last update.

get_feature(attribute: str | property | Callable) Feature | None

Get Feature for a module attribute or None if not supported.

has_feature(attribute: str | property | Callable) bool

Return True if the module attribute feature is supported.

abstract query() dict

Query to execute during the update cycle.

The inheriting modules implement this to include their wanted queries to the query that gets executed when Device.update() gets called.

abstract async set_time(dt: datetime) dict[source]

Set the device time.

abstract property time: datetime

Return timezone aware current device time.

abstract property timezone: tzinfo

Return current timezone.

Protocols and transports

class kasa.protocols.BaseProtocol(*, transport: BaseTransport)[source]

Base class for all TP-Link Smart Home communication.

abstract async close() None[source]

Close the protocol. Abstract method to be overriden.

property config: DeviceConfig

Return the connection parameters the device is using.

abstract async query(request: str | dict, retry_count: int = 3) dict[source]

Query the device for the protocol. Abstract method to be overriden.

class kasa.protocols.IotProtocol(*, transport: BaseTransport)[source]

Class for the legacy TPLink IOT KASA Protocol.

BACKOFF_SECONDS_AFTER_TIMEOUT = 1
async close() None[source]

Close the underlying transport.

property config: DeviceConfig

Return the connection parameters the device is using.

async query(request: str | dict, retry_count: int = 3) dict[source]

Query the device retrying for retry_count on failure.

class kasa.protocols.SmartProtocol(*, transport: BaseTransport)[source]

Class for the new TPLink SMART protocol.

BACKOFF_SECONDS_AFTER_TIMEOUT = 1
DEFAULT_MULTI_REQUEST_BATCH_SIZE = 5
async close() None[source]

Close the underlying transport.

property config: DeviceConfig

Return the connection parameters the device is using.

get_smart_request(method: str, params: dict | None = None) str[source]

Get a request message as a string.

async query(request: str | dict, retry_count: int = 3) dict[source]

Query the device retrying for retry_count on failure.

class kasa.transports.BaseTransport(*, config: DeviceConfig)[source]

Base class for all TP-Link protocol transports.

DEFAULT_TIMEOUT = 5
abstract async close() None[source]

Close the transport. Abstract method to be overriden.

abstract property credentials_hash: str | None

The hashed credentials used by the transport.

abstract property default_port: int

The default port for the transport.

abstract async reset() None[source]

Reset internal state.

abstract async send(request: str) dict[source]

Send a message to the device and return a response.

class kasa.transports.XorTransport(*, config: DeviceConfig)[source]

XorTransport class.

BLOCK_SIZE = 4
DEFAULT_PORT: int = 9999
DEFAULT_TIMEOUT = 5
async close() None[source]

Close the connection.

close_without_wait() None[source]

Close the connection without waiting for the connection to close.

property credentials_hash: str | None

The hashed credentials used by the transport.

property default_port: int

Default port for the transport.

async reset() None[source]

Reset the transport.

The transport cannot be reset so we must close instead.

async send(request: str) dict[source]

Send a message to the device and return a response.

class kasa.transports.KlapTransport(*, config: DeviceConfig)[source]

Implementation of the KLAP encryption protocol.

KLAP is the name used in device discovery for TP-Link’s new encryption protocol, used by newer firmware versions.

DEFAULT_PORT: int = 80
DEFAULT_TIMEOUT = 5
async close() None[source]

Close the http client and reset internal state.

property credentials_hash: str | None

The hashed credentials used by the transport.

property default_port: int

Default port for the transport.

static generate_auth_hash(creds: Credentials) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

static generate_owner_hash(creds: Credentials) bytes[source]

Return the MD5 hash of the username in this object.

static handshake1_seed_auth_hash(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

static handshake2_seed_auth_hash(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

async perform_handshake() None[source]

Perform handshake1 and handshake2.

Sets the encryption_session if successful.

async perform_handshake1() tuple[bytes, bytes, bytes][source]

Perform handshake1.

async perform_handshake2(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) KlapEncryptionSession[source]

Perform handshake2.

async reset() None[source]

Reset internal handshake state.

async send(request: str) Generator[Future, None, dict[str, str]][source]

Send the request.

class kasa.transports.KlapTransportV2(*, config: DeviceConfig)[source]

Implementation of the KLAP encryption protocol with v2 hanshake hashes.

DEFAULT_PORT: int = 80
DEFAULT_TIMEOUT = 5
async close() None

Close the http client and reset internal state.

property credentials_hash: str | None

The hashed credentials used by the transport.

property default_port: int

Default port for the transport.

static generate_auth_hash(creds: Credentials) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

static generate_owner_hash(creds: Credentials) bytes

Return the MD5 hash of the username in this object.

static handshake1_seed_auth_hash(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

static handshake2_seed_auth_hash(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) bytes[source]

Generate an md5 auth hash for the protocol on the supplied credentials.

async perform_handshake() None

Perform handshake1 and handshake2.

Sets the encryption_session if successful.

async perform_handshake1() tuple[bytes, bytes, bytes]

Perform handshake1.

async perform_handshake2(local_seed: bytes, remote_seed: bytes, auth_hash: bytes) KlapEncryptionSession

Perform handshake2.

async reset() None

Reset internal handshake state.

async send(request: str) Generator[Future, None, dict[str, str]]

Send the request.

class kasa.transports.AesTransport(*, config: DeviceConfig)[source]

Implementation of the AES encryption protocol.

AES is the name used in device discovery for TP-Link’s TAPO encryption protocol, sometimes used by newer firmware versions on kasa devices.

COMMON_HEADERS = {'Accept': 'application/json', 'Content-Type': 'application/json', 'requestByApp': 'true'}
CONTENT_LENGTH = 'Content-Length'
DEFAULT_PORT: int = 80
DEFAULT_TIMEOUT = 5
KEY_PAIR_CONTENT_LENGTH = 314
async close() None[source]

Close the http client and reset internal state.

property credentials_hash: str | None

The hashed credentials used by the transport.

property default_port: int

Default port for the transport.

static hash_credentials(login_v2: bool, credentials: Credentials) tuple[str, str][source]

Hash the credentials.

async perform_handshake() None[source]

Perform the handshake.

async perform_login() None[source]

Login to the device.

async reset() None[source]

Reset internal handshake and login state.

async send(request: str) dict[str, Any][source]

Send the request.

async send_secure_passthrough(request: str) dict[str, Any][source]

Send encrypted message as passthrough.

async try_login(login_params: dict[str, Any]) None[source]

Try to login with supplied login_params.

Errors and exceptions

class kasa.exceptions.KasaException[source]

Base exception for library errors.

class kasa.exceptions.DeviceError(*args: Any, **kwargs: Any)[source]

Base exception for device errors.

class kasa.exceptions.AuthenticationError(*args: Any, **kwargs: Any)[source]

Base exception for device authentication errors.

class kasa.exceptions.UnsupportedDeviceError(*args: Any, **kwargs: Any)[source]

Exception for trying to connect to unsupported devices.

class kasa.exceptions.TimeoutError[source]

Timeout exception for device errors.