Class KasaDevice
- Namespace
- KasaTapoClient
- Assembly
- KasaTapoClient.dll
Represents a single TP-Link Kasa or Tapo device.
public sealed class KasaDevice : IDisposable
- Inheritance
-
KasaDevice
- Implements
- Inherited Members
Properties
Alarm
Gets the module-style alarm wrapper.
public AlarmModule Alarm { get; }
Property Value
AlarmState
Gets the most recent normalized alarm state, when supported by the device.
public AlarmState? AlarmState { get; }
Property Value
Alias
Gets the best known alias for the device.
public string Alias { get; }
Property Value
AutoOff
Gets the module-style auto-off wrapper.
public AutoOffModule AutoOff { get; }
Property Value
AutoOffState
Gets the most recent auto-off state, when supported by the device.
public AutoOffState? AutoOffState { get; }
Property Value
AvailableLightEffects
Gets the available light effects reported by the device.
public IReadOnlyList<LightEffectDefinition> AvailableLightEffects { get; }
Property Value
ChildDevices
Gets wrapper objects for child devices.
public IReadOnlyList<ChildDevice> ChildDevices { get; }
Property Value
ChildLock
Gets the module-style child-lock wrapper.
public ChildLockModule ChildLock { get; }
Property Value
ChildLockState
Gets the most recent child-lock state, when supported by the device.
public ChildLockState? ChildLockState { get; }
Property Value
ChildSetup
Gets the module-style child setup wrapper for smart hub devices.
public ChildSetupModule ChildSetup { get; }
Property Value
Children
Gets the child devices reported by the device.
public IReadOnlyList<ChildDeviceInfo> Children { get; }
Property Value
Cloud
Gets the module-style cloud wrapper.
public CloudModule Cloud { get; }
Property Value
CloudState
Gets the most recent normalized cloud-connection state, when supported by the device.
public CloudConnectionState? CloudState { get; }
Property Value
Configuration
Gets the connection settings for the device.
public DeviceConfiguration Configuration { get; }
Property Value
Countdown
Gets the module-style countdown wrapper.
public CountdownModule Countdown { get; }
Property Value
DeviceType
Gets the inferred device family.
public DeviceType DeviceType { get; }
Property Value
Energy
Gets the module-style energy wrapper.
public EnergyModule Energy { get; }
Property Value
EnergyUsage
Gets the most recent normalized energy usage information, when supported by the device.
public EnergyUsage? EnergyUsage { get; }
Property Value
Fan
Gets the module-style fan wrapper.
public FanModule Fan { get; }
Property Value
FanState
Gets the most recent normalized fan state, when supported by the device.
public FanState? FanState { get; }
Property Value
Features
Gets the current feature collection derived from the latest device state.
public IReadOnlyList<DeviceFeature> Features { get; }
Property Value
Firmware
Gets the module-style firmware wrapper.
public FirmwareModule Firmware { get; }
Property Value
FirmwareState
Gets the most recent normalized firmware state, when supported by the device.
public FirmwareState? FirmwareState { get; }
Property Value
HomeKit
Gets the module-style HomeKit wrapper.
public HomeKitModule HomeKit { get; }
Property Value
HomeKitSetup
Gets the most recent HomeKit setup information, when supported by the device.
public HomeKitSetupInfo? HomeKitSetup { get; }
Property Value
Host
Gets the current device host.
public string Host { get; }
Property Value
IsOn
Gets a value indicating whether the device is currently on.
public bool? IsOn { get; }
Property Value
- bool?
Led
Gets the module-style LED wrapper.
public LedModule Led { get; }
Property Value
LedState
Gets the most recent LED state, when supported by the device.
public LedState? LedState { get; }
Property Value
Light
Gets the module-style light wrapper.
public LightModule Light { get; }
Property Value
LightEffect
Gets the most recent normalized light effect state, when supported by the device.
public LightEffectState? LightEffect { get; }
Property Value
LightPreset
Gets the module-style light preset wrapper.
public LightPresetModule LightPreset { get; }
Property Value
LightPresetState
Gets the most recent normalized light preset module state, when supported by the device.
public LightPresetState? LightPresetState { get; }
Property Value
LightState
Gets the most recent normalized light state, when supported by the device.
public LightState? LightState { get; }
Property Value
LightStripEffect
Gets the module-style light strip effect wrapper.
public LightStripEffectModule LightStripEffect { get; }
Property Value
LightStripEffectState
Gets the most recent normalized light strip effect module state, when supported by the device.
public LightStripEffectState? LightStripEffectState { get; }
Property Value
LightTransition
Gets the module-style light transition wrapper.
public LightTransitionModule LightTransition { get; }
Property Value
LightTransitionState
Gets the most recent normalized light transition module state, when supported by the device.
public LightTransitionState? LightTransitionState { get; }
Property Value
Matter
Gets the module-style Matter wrapper.
public MatterModule Matter { get; }
Property Value
MatterSetup
Gets the most recent Matter setup information, when supported by the device.
public MatterSetupInfo? MatterSetup { get; }
Property Value
OnSince
Gets the derived timestamp for when the device was turned on, when reported.
public DateTimeOffset? OnSince { get; }
Property Value
OverheatProtection
Gets the module-style overheat protection wrapper.
public OverheatProtectionModule OverheatProtection { get; }
Property Value
OverheatProtectionState
Gets the most recent normalized overheat protection state, when supported by the device.
public OverheatProtectionState? OverheatProtectionState { get; }
Property Value
PowerProtection
Gets the module-style power protection wrapper.
public PowerProtectionModule PowerProtection { get; }
Property Value
PowerProtectionState
Gets the most recent normalized power protection state, when supported by the device.
public PowerProtectionState? PowerProtectionState { get; }
Property Value
Rssi
Gets the most recent host RSSI value in dBm when the device reports it.
public int? Rssi { get; }
Property Value
- int?
RuleState
Gets the most recent normalized rule module state, when supported by the device.
public RuleModuleState? RuleState { get; }
Property Value
Rules
Gets the module-style rules wrapper.
public RuleModule Rules { get; }
Property Value
Speaker
Gets the module-style speaker wrapper.
public SpeakerModule Speaker { get; }
Property Value
SpeakerState
Gets the most recent normalized speaker state, when supported by the device.
public SpeakerState? SpeakerState { get; }
Property Value
SupportsLightEffects
Gets a value indicating whether the device reports light-effect capability.
public bool SupportsLightEffects { get; }
Property Value
System
Gets the module-style system wrapper.
public SystemModule System { get; }
Property Value
SystemInfo
Gets the most recent normalized system information, or null until UpdateAsync(CancellationToken) succeeds.
public DeviceSystemInfo? SystemInfo { get; }
Property Value
Time
Gets the module-style time wrapper.
public TimeModule Time { get; }
Property Value
TimeState
Gets the most recent normalized device-local time state, when supported by the device.
public DeviceTimeState? TimeState { get; }
Property Value
Usage
Gets the module-style usage wrapper.
public UsageModule Usage { get; }
Property Value
Methods
ClearLightEffectAsync(CancellationToken)
Disables the current lighting effect and refreshes state.
public Task ClearLightEffectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light effect state has been refreshed.
Dispose()
Releases transport resources owned by the device.
public void Dispose()
ExecuteCommandAsync(string, CancellationToken)
Executes a raw JSON command against the device.
public Task<string> ExecuteCommandAsync(string commandJson, CancellationToken cancellationToken = default)
Parameters
commandJsonstringThe command payload to send.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
Exceptions
- ArgumentException
Thrown when
commandJsonis empty or whitespace.
GetChild(string)
Returns a child device by identifier when present.
public ChildDeviceInfo? GetChild(string childDeviceId)
Parameters
childDeviceIdstringThe child device identifier.
Returns
- ChildDeviceInfo
The matching child device, or null if not found.
GetChildDevice(string)
Returns a child-device wrapper by identifier when present.
public ChildDevice? GetChildDevice(string childDeviceId)
Parameters
childDeviceIdstringThe child device identifier.
Returns
- ChildDevice
The matching child-device wrapper, or null if not found.
GetFeature(string)
Returns a feature by identifier when present.
public DeviceFeature? GetFeature(string featureId)
Parameters
featureIdstringThe feature identifier.
Returns
- DeviceFeature
The matching feature, or null if not found.
GetScannedChildDevicesAsync(CancellationToken)
Gets the currently detected child devices from the smart hub scan state.
public Task<ChildSetupScanResult> GetScannedChildDevicesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task<ChildSetupScanResult>
The detected child devices and supported categories reported by the hub.
Exceptions
- InvalidOperationException
Thrown when the device does not support smart hub child setup operations.
PairScannedChildDevicesAsync(IReadOnlyList<DetectedChildDevice>, CancellationToken)
Pairs the specified detected child devices with the smart hub.
public Task<IReadOnlyList<DetectedChildDevice>> PairScannedChildDevicesAsync(IReadOnlyList<DetectedChildDevice> devices, CancellationToken cancellationToken = default)
Parameters
devicesIReadOnlyList<DetectedChildDevice>The detected child devices to pair.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task<IReadOnlyList<DetectedChildDevice>>
The subset of requested devices that were confirmed as added after refresh.
Exceptions
- InvalidOperationException
Thrown when the device does not support smart hub child setup operations.
ScanForChildDevicesAsync(int, CancellationToken)
Starts a smart hub child-device scan, waits for the requested interval, and returns the detected devices.
public Task<ChildSetupScanResult> ScanForChildDevicesAsync(int timeoutSeconds = 10, CancellationToken cancellationToken = default)
Parameters
timeoutSecondsintThe number of seconds to wait after beginning the scan before reading detected devices.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task<ChildSetupScanResult>
The detected child devices and supported categories reported by the hub.
Exceptions
- InvalidOperationException
Thrown when the device does not support smart hub child setup operations.
SetBrightnessAsync(int, CancellationToken)
Sets the brightness percentage and refreshes state.
public Task SetBrightnessAsync(int brightness, CancellationToken cancellationToken = default)
Parameters
brightnessintThe brightness percentage from 0 through 100.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light state has been refreshed.
Exceptions
- ArgumentOutOfRangeException
Thrown when
brightnessis outside the inclusive range of 0 through 100.
SetColorTemperatureAsync(int, CancellationToken)
Sets the color temperature in kelvin and refreshes state.
public Task SetColorTemperatureAsync(int colorTemperature, CancellationToken cancellationToken = default)
Parameters
colorTemperatureintThe color temperature, in kelvin, to apply to the light.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light state has been refreshed.
Exceptions
- ArgumentOutOfRangeException
Thrown when
colorTemperatureis zero or negative.
SetHsvAsync(int, int, int, CancellationToken)
Sets the hue, saturation, and value components and refreshes state.
public Task SetHsvAsync(int hue, int saturation, int value, CancellationToken cancellationToken = default)
Parameters
hueintThe hue component from 0 through 360.
saturationintThe saturation component from 0 through 100.
valueintThe value or brightness component from 0 through 100.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light state has been refreshed.
Exceptions
- ArgumentOutOfRangeException
Thrown when
hue,saturation, orvaluefalls outside its supported range.
SetLightEffectAsync(string, CancellationToken)
Enables a lighting effect by device-specific name or identifier and refreshes state.
public Task SetLightEffectAsync(string effect, CancellationToken cancellationToken = default)
Parameters
effectstringThe device-specific light effect name or identifier.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light effect state has been refreshed.
Exceptions
- ArgumentException
Thrown when
effectis empty or whitespace.
TurnChildOffAsync(string, CancellationToken)
Turns a child device off and refreshes the parent device state.
public Task TurnChildOffAsync(string childDeviceId, CancellationToken cancellationToken = default)
Parameters
childDeviceIdstringThe child device identifier.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the child device and parent state have been refreshed.
TurnChildOnAsync(string, CancellationToken)
Turns a child device on and refreshes the parent device state.
public Task TurnChildOnAsync(string childDeviceId, CancellationToken cancellationToken = default)
Parameters
childDeviceIdstringThe child device identifier.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the child device and parent state have been refreshed.
TurnLightOffAsync(CancellationToken)
Turns the light off and refreshes state.
public Task TurnLightOffAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light state has been refreshed.
TurnLightOnAsync(CancellationToken)
Turns the light on and refreshes state.
public Task TurnLightOnAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the light state has been refreshed.
TurnOffAsync(CancellationToken)
Turns the device off and refreshes its state.
public Task TurnOffAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the device has been updated.
TurnOnAsync(CancellationToken)
Turns the device on and refreshes its state.
public Task TurnOnAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the device has been updated.
UnpairChildDeviceAsync(string, CancellationToken)
Removes a child device from the smart hub and refreshes state.
public Task UnpairChildDeviceAsync(string childDeviceId, CancellationToken cancellationToken = default)
Parameters
childDeviceIdstringThe child device identifier to remove.
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the child device has been removed and state refreshed.
Exceptions
- InvalidOperationException
Thrown when the device does not support smart hub child setup operations.
UpdateAsync(CancellationToken)
Refreshes SystemInfo by querying the device.
public Task UpdateAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.
Returns
- Task
A task that completes when the device state has been refreshed.
UpdateEnergyUsageAsync(CancellationToken)
Refreshes EnergyUsage when the device exposes emeter telemetry.
public Task<bool> UpdateEnergyUsageAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenThe cancellation token for the operation.