mihai-dinculescu / tapo

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).
MIT License
313 stars 30 forks source link

get_device_info broken for L900 #191

Closed tmstorey closed 2 months ago

tmstorey commented 3 months ago

Reproduction:

use tapo::ApiClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
  let tapo_username = env::var("TAPO_USERNAME")?;
  let tapo_password = env::var("TAPO_PASSWORD")?;
  let ip_address = env::var("IP_ADDRESS")?;

  let device = ApiClient::new(tapo_username, tapo_password)
    .l900(ip_address)
    .await?;
  let device_info = device.get_device_info().await?;

Result: Error: Serde(Error("missing field `dynamic_light_effect_enable`", line: 1, column: 1052))

get_device_info_json is working correctly.

The issue seems to be that api_client.rs is implementing L900 support using a ColorLightHandler rather than a ColorLightStripHandler. The L900 model is in fact a light strip and doesn't seem to return the dynamic_light_effect_enable and dynamic_light_effect_id fields in the JSON, which Serde expects.

Changing this in the ApiClient::l900 function builds in Rust and fixes the issue, but breaks the Python build as tapo-py doesn't support light strips.

mihai-dinculescu commented 3 months ago

Thanks for reporting this. I have added the L900 support without having one, so I'm not surprised I've missed a few things. I suspect that adding a new LightStripHandler and LightStripResult pair would be the appropriate fix.

Can you please paste the output of get_device_info_json?

tmstorey commented 3 months ago

Here's the output (with a few details redacted):

{
  "avatar": "light_strip", 
  "brightness": 30, 
  "color_temp": 9000, 
  "color_temp_range": [9000, 9000], 
  "default_states": {
    "state": {
      "brightness": 30, 
      "color_temp": 9000, 
      "hue": 0, 
      "saturation": 100
    }
    ,
    "type": "last_states"
  }
  ,
  "device_id": "",
  "device_on": true,
  "fw_id": "00000000000000000000000000000000",
  "fw_ver": "1.1.0 Build 230905 Rel.184939",
  "has_set_location_info": true,
  "hue": 0,
  "hw_id": "",
  "hw_ver": "1.0",
  "ip": "192.168.0.20",
  "lang": "en_US",
  "latitude": 0,
  "lighting_effect": {
    "brightness": 100, 
    "custom": 1, 
    "display_colors": [[359, 85, 100]], 
    "enable": 0, 
    "id": "b7a3f0e57258404dae904d77c9ffc6fa", 
    "name": "My Custom Sequence Effect"
  }
  ,
  "longitude": 0,
  "mac": "24-2F-D0-18-8A-5E",
  "model": "L900",
  "music_rhythm_enable": false,
  "music_rhythm_mode": "single_lamp",
  "nickname": "",
  "oem_id": "",
  "overheated": false,
  "region": "Australia/Sydney",
  "rssi": -61,
  "saturation": 100,
  "signal_level": 2,
  "specs": "",
  "ssid": "",
  "time_diff": 600,
  "type": "SMART.TAPOBULB"
}