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, on_discovered_raw: Callable[[DiscoveredRaw], None] | 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
on_discovered_raw – Optional callback once discovered json is loaded before any attempt to deserialize it and create devices
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_discovered_raw: Callable[[DiscoveredRaw], None] | 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 useDevice.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
on_discovered_raw – Optional callback once discovered json is loaded before any attempt to deserialize it and create devices
on_unsupported – Optional callback when unsupported devices are discovered
- 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()orDiscover.discover_single().- Config
alias of
DeviceConfig
- ConnectionParameters
alias of
DeviceConnectionParameters
- EncryptionType
alias of
DeviceEncryptionType
- Family
alias of
DeviceFamily
- Type
alias of
DeviceType
- abstract property alias: str | None
Returns the device alias or nickname.
- 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_info: DeviceInfo
Return device info.
- property device_type: DeviceType
Return the device type.
- abstract async factory_reset() None[source]
Reset device back to factory settings.
Note, this does not downgrade the firmware.
- get_child_device(name_or_id: str) Device | None[source]
Return child device by its device_id or alias.
- 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 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 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.
- property region: str | None
Returns the device region.
- abstract property rssi: int | None
Return the rssi.
- 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 update_from_discover_info(info: dict) None[source]
Update state from info from the discover call.
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>, 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().
- property uses_http: bool
True if the device uses http.
- class kasa.DeviceFamily(*values)[source]
Encrypt type enum.
- IotIpCamera = 'IOT.IPCAMERA'
- IotSmartBulb = 'IOT.SMARTBULB'
- IotSmartPlugSwitch = 'IOT.SMARTPLUGSWITCH'
- SmartIpCamera = 'SMART.IPCAMERA'
- SmartKasaHub = 'SMART.KASAHUB'
- SmartKasaPlug = 'SMART.KASAPLUG'
- SmartKasaSwitch = 'SMART.KASASWITCH'
- SmartTapoBulb = 'SMART.TAPOBULB'
- SmartTapoChime = 'SMART.TAPOCHIME'
- SmartTapoDoorbell = 'SMART.TAPODOORBELL'
- SmartTapoHub = 'SMART.TAPOHUB'
- SmartTapoPlug = 'SMART.TAPOPLUG'
- SmartTapoRobovac = 'SMART.TAPOROBOVAC'
- SmartTapoSwitch = 'SMART.TAPOSWITCH'
- class kasa.DeviceConnectionParameters(device_family: DeviceFamily, encryption_type: DeviceEncryptionType, login_version: int | None = None, https: bool = False, http_port: int | None = None)[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, http_port: int | None = None) DeviceConnectionParameters[source]
Return connection parameters from string values.
- http_port: int | None = None
- https: bool = False
- login_version: int | None = None
- to_dict()
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.
- 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.
- 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: Device | Module | None = 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(*values)[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(*values)[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, andmaximum_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: Device | Module | None = None
Container storing the data, this overrides ‘device’ for getters
- 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
- 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.
- 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.Alarm(device: Device, module: str)[source]
Base interface to represent an alarm module.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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 active: bool
Return true if alarm is active.
- abstract property alarm_duration: Annotated[int, FeatureAttribute]
Return alarm duration.
- abstract property alarm_sound: Annotated[str, FeatureAttribute]
Return current alarm sound.
- abstract property alarm_sounds: list[str]
Return list of available alarm sounds.
- abstract property alarm_volume: Annotated[int, FeatureAttribute]
Return alarm volume.
- 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 async play(*, duration: int | None = None, volume: int | None = None, sound: str | None = None) dict[source]
Play alarm.
The optional duration, volume, and sound to override the device settings. duration is in seconds. See alarm_sounds for the list of sounds available for the device.
- 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_alarm_duration(duration: int) Annotated[dict, FeatureAttribute][source]
Set alarm duration.
- abstract async set_alarm_sound(sound: str) Annotated[dict, FeatureAttribute][source]
Set alarm sound.
See alarm_sounds for list of available sounds.
- class kasa.interfaces.ChildSetup(device: Device, module: str)[source]
Interface for child setup on hubs.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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 property supported_categories: list[str]
Supported child device categories.
- class kasa.interfaces.Energy(device: Device, module: str)[source]
Base interface to represent an Energy module.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- class ModuleFeature(*values)[source]
Features supported by the device.
- CONSUMPTION_TOTAL = 2
Device reports
consumption_total
- PERIODIC_STATS = 4
Device reports periodic stats via
get_daily_stats()andget_monthly_stats()
- VOLTAGE_CURRENT = 1
Device reports
voltageandcurrent
- 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.
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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 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.
- 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[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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.
- class kasa.interfaces.Led(device: Device, module: str)[source]
Base interface to represent a LED module.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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.
- class kasa.interfaces.Light(device: Device, module: str)[source]
Base class for TP-Link Light.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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.
- 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 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.
- class kasa.interfaces.LightEffect(device: Device, module: str)[source]
Interface to represent a light effect module.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LIGHT_EFFECTS_UNNAMED_CUSTOM = 'Custom'
- Led: Final[ModuleName[interfaces.Led]] = 'Led'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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 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 useset_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[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PRESET_NOT_SET = 'Not set'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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.
- 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[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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_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(*values)[source]
Thermostat state.
- Calibrating = 'progress_calibration'
- Heating = 'heating'
- Hold = 'hold_on'
- Idle = 'idle'
- Off = 'off'
- Shutdown = 'shutdown'
- Unknown = 'unknown'
- class kasa.interfaces.Time(device: Device, module: str)[source]
Base class for tplink time module.
- Alarm: Final[ModuleName[interfaces.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'
- ChildLock: Final[ModuleName[smart.ChildLock]] = 'ChildLock'
- ChildProtection: Final[ModuleName[smart.ChildProtection]] = 'ChildProtection'
- ChildSetup: Final[ModuleName[interfaces.ChildSetup]] = 'ChildSetup'
- Clean: Final[ModuleName[smart.Clean]] = 'Clean'
- CleanRecords: Final[ModuleName[smart.CleanRecords]] = 'CleanRecords'
- Cloud: Final[ModuleName[smart.Cloud]] = 'Cloud'
- Color: Final[ModuleName[smart.Color]] = 'Color'
- ColorTemperature: Final[ModuleName[smart.ColorTemperature]] = 'ColorTemperature'
- Consumables: Final[ModuleName[smart.Consumables]] = 'Consumables'
- ContactSensor: Final[ModuleName[smart.ContactSensor]] = 'ContactSensor'
- DeviceModule: Final[ModuleName[smart.DeviceModule]] = 'DeviceModule'
- Dustbin: Final[ModuleName[smart.Dustbin]] = 'Dustbin'
- Energy: Final[ModuleName[interfaces.Energy]] = 'Energy'
- Fan: Final[ModuleName[interfaces.Fan]] = 'Fan'
- Firmware: Final[ModuleName[smart.Firmware]] = 'Firmware'
- FrostProtection: Final[ModuleName[smart.FrostProtection]] = 'FrostProtection'
- HomeKit: Final[ModuleName[smart.HomeKit]] = 'HomeKit'
- 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'
- IotDimmer: Final[ModuleName[iot.Dimmer]] = 'dimmer'
- IotHomeKit: Final[ModuleName[iot.HomeKit]] = 'homekit'
- 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'
- LensMask: Final[ModuleName[smartcam.LensMask]] = 'LensMask'
- Light: Final[ModuleName[interfaces.Light]] = 'Light'
- LightEffect: Final[ModuleName[interfaces.LightEffect]] = 'LightEffect'
- LightPreset: Final[ModuleName[interfaces.LightPreset]] = 'LightPreset'
- LightTransition: Final[ModuleName[smart.LightTransition]] = 'LightTransition'
- Matter: Final[ModuleName[smart.Matter]] = 'Matter'
- Mop: Final[ModuleName[smart.Mop]] = 'Mop'
- MotionSensor: Final[ModuleName[smart.MotionSensor]] = 'MotionSensor'
- PanTilt: Final[ModuleName[smartcam.PanTilt]] = 'PanTilt'
- PowerProtection: Final[ModuleName[smart.PowerProtection]] = 'PowerProtection'
- ReportMode: Final[ModuleName[smart.ReportMode]] = 'ReportMode'
- SmartLightEffect: Final[ModuleName[smart.SmartLightEffect]] = 'LightEffect'
- Speaker: Final[ModuleName[smart.Speaker]] = 'Speaker'
- 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 property time: datetime
Return timezone aware current device time.
- abstract property timezone: tzinfo
Return current timezone.
Protocols and transports
Package containing all supported protocols.
- 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.
- async query(request: str | dict, retry_count: int = 3) dict[source]
Query the device retrying for retry_count on failure.
- class kasa.protocols.SmartCamProtocol(*, transport: BaseTransport)[source]
Class for SmartCam Protocol.
- async close() None[source]
Close the underlying transport.
- 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.
- 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.
Package containing all supported transports.
- class kasa.transports.AesEncyptionSession(key: bytes, iv: bytes)[source]
Class for an AES encryption session.
- static create_from_keypair(handshake_key: str, keypair: KeyPair) AesEncyptionSession[source]
Create the encryption session.
- decrypt(data: str | bytes) str[source]
Decrypt the message.
- encrypt(data: bytes) bytes[source]
Encrypt the message.
- 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
- KEY_PAIR_CONTENT_LENGTH = 314
- SESSION_COOKIE_NAME = 'TP_SESSIONID'
- TIMEOUT_COOKIE_NAME = 'TIMEOUT'
- 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.
- 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.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.
- CIPHERS = 'AES256-GCM-SHA384:AES256-SHA256:AES128-GCM-SHA256:AES128-SHA256:AES256-SHA'
- DEFAULT_HTTPS_PORT: int = 4433
- DEFAULT_PORT: int = 80
- SESSION_COOKIE_NAME = 'TP_SESSIONID'
- TIMEOUT_COOKIE_NAME = 'TIMEOUT'
- 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.
- static generate_auth_hash(creds: Credentials) bytes[source]
Generate an md5 auth hash for the protocol on the supplied credentials.
- 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.
- class kasa.transports.LinkieTransportV2(*, config: DeviceConfig)[source]
Implementation of the Linkie encryption protocol.
Linkie is used as the endpoint for TP-Link’s camera encryption protocol, used by newer firmware versions.
- CIPHERS = 'AES256-GCM-SHA384:AES256-SHA256:AES128-GCM-SHA256:AES128-SHA256:AES256-SHA'
- DEFAULT_PORT: int = 10443
- 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.
- async reset() None[source]
Reset the transport.
NOOP for this transport.
- async send(request: str) dict[source]
Send a message to the device and return a response.
- class kasa.transports.SslAesTransport(*, 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.
- CIPHERS = 'ECDHE-RSA-AES128-GCM-SHA256:AES256-GCM-SHA384:AES256-SHA256:AES128-GCM-SHA256:AES128-SHA256:AES256-SHA'
- COMMON_HEADERS = {'Accept': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/json; charset=UTF-8', 'User-Agent': 'Tapo CameraClient Android', 'requestByApp': 'true'}
- DEFAULT_PORT: int = 443
- DEFAULT_TIMEOUT = 10
- 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_confirm_hash(local_nonce: str, server_nonce: str, pwd_hash: str) str[source]
Generate an auth hash for the protocol on the supplied credentials.
- static generate_digest_password(local_nonce: str, server_nonce: str, pwd_hash: str) str[source]
Generate an auth hash for the protocol on the supplied credentials.
- static generate_encryption_token(token_type: str, local_nonce: str, server_nonce: str, pwd_hash: str) bytes[source]
Generate encryption token.
- static generate_tag(request: str, local_nonce: str, pwd_hash: str, seq: int) str[source]
Generate the tag header from the request for the header.
- async perform_handshake() None[source]
Perform the handshake.
- async perform_handshake1() tuple[str, str, str] | None[source]
Perform the handshake1.
- async perform_handshake2(local_nonce: str, server_nonce: str, pwd_hash: str) None[source]
Perform the handshake.
- async reset() None[source]
Reset internal handshake 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 send_unencrypted(request: str) dict[str, Any][source]
Send encrypted message as passthrough.
- async try_perform_less_secure_login(username: str, password: str) bool[source]
Perform the md5 login.
- async try_send_handshake1(username: str, local_nonce: str) dict[source]
Perform the handshake.
- class kasa.transports.SslTransport(*, config: DeviceConfig)[source]
Implementation of the cleartext transport protocol.
This transport uses HTTPS without any further payload encryption.
- BACKOFF_SECONDS_AFTER_LOGIN_ERROR = 1
- COMMON_HEADERS = {'Content-Type': 'application/json'}
- DEFAULT_PORT: int = 4433
- async close() None[source]
Close the http client and reset internal state.
- property credentials_hash: str
The hashed credentials used by the transport.
- property default_port: int
Default port for the transport.
- static hash_credentials(credentials: Credentials) tuple[str, str][source]
Hash the credentials.
- async perform_login() None[source]
Login to the device.
- async reset() None[source]
Reset internal login state.
- async send(request: str) dict[str, Any][source]
Send the request.
- async send_request(request: str) dict[str, Any][source]
Send request.
- async try_login(login_params: dict[str, Any]) None[source]
Try to login with supplied login_params.
- class kasa.transports.XorEncryption[source]
XorEncryption class.
- INITIALIZATION_VECTOR = 171
- static decrypt(ciphertext: bytes) str[source]
Decrypt a response of a TP-Link Smart Home Device.
- Parameters:
ciphertext – encrypted response data
- Returns:
plaintext response
- static encrypt(request: str) bytes[source]
Encrypt a request for a TP-Link Smart Home Device.
- Parameters:
request – plaintext request data
- Returns:
ciphertext to be send over wire, in bytes
- class kasa.transports.XorTransport(*, config: DeviceConfig)[source]
XorTransport class.
- BLOCK_SIZE = 4
- DEFAULT_PORT: int = 9999
- 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.
Errors and exceptions
- 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.