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
347 stars 35 forks source link

trigger logs doesn't retrieve all logs #244

Open francisT90 opened 1 month ago

francisT90 commented 1 month ago

Hi, I am trying to get the logs from a T100 device using the example in the H100 in the rust app and I get them but I don't get them all. Is there a maximum number of logs that can be retrieved?

I have modify the code so the call is:

let trigger_logs = t100.get_trigger_logs(5000, 0).await?;

I only have like 1400 logs registered so it should retrieve them all rather than only 907.

Is there a way to get them all?

Thanks for this, it is quite useful!

mihai-dinculescu commented 1 month ago

I'm not sure, as I haven't had a device with so many logs. Can you please try with a page_size of, say, 500 and then fetch the subsequent pages by providing the oldest (should be the last) id as start_id?

francisT90 commented 1 month ago

Hi, I have tried different things but I think the issue is like the API is not returning certain info as it grows or as time passes?

I have done a test today and I have retrieved the logs from 1603 to 725, then I try to retrieve 3 logs starting on id 725 and I get only one, the number 725.

I can't find anything on the internet any guidance to where could I find any more info would be much appreciated.

All the best,

mihai-dinculescu commented 6 days ago

Sorry for having taken so long to reply.

Can you please paste the output of

                let mut cont = true;
                let mut start_id = 0;
                while cont {
                    let trigger_logs = t110.get_trigger_logs(100, start_id).await?;
                    println!("start id {:?}", trigger_logs.start_id);
                    println!("sum {:?}", trigger_logs.sum);
                    println!("len {:?}", trigger_logs.logs.len());
                    let last_log = trigger_logs.logs.last().unwrap();
                    start_id = match last_log {
                        T110Log::Close { id, timestamp } => {
                            println!("{timestamp}");
                            *id
                        }
                        T110Log::Open { id, timestamp } => {
                            println!("{timestamp}");
                            *id
                        }
                        T110Log::KeepOpen { id, timestamp } => {
                            println!("{timestamp}");
                            *id
                        }
                    };
                    println!("next start id {:?}", start_id);

                    cont = trigger_logs.logs.len() > 1;
                }