Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History Data for last n records #28

Merged
merged 1 commit into from
Jan 8, 2021
Merged

History Data for last n records #28

merged 1 commit into from
Jan 8, 2021

Conversation

53RT
Copy link

@53RT 53RT commented Jan 6, 2021

Hi,

I was curious what the other characteristics mean and was partially lucky. Mainly the issue from MiTemperature2 helped me to understand how the Mi Home App reads the daily statistics so fast. I created a bluetooth dump and noticed, that an index is set to total_records - 23 to fetch the 24 most recent history_data which are then displayed.

The function relies on two things. The total number of records the device has recorded (earlier records might be already deleted as it seems that the device can store about 4650 records) and the current number of records stored. Those information can be read with client.num_stored_entries.
With the client.history_index property an index in the range [total_records - current_records + 1, total_records] can be set to retrieve a partial amount of the recorded entries.

I added an example in the Readme that shows how to read the ten most recent entries. Note if the client object already exists and client.history_data was already called, setting an index and calling it again will update the ordered_dict that holds the history_data with the most recent entries so it might be, that the data returned is longer than expected as it includes entries from previous calls.

I thought this feature could be interesting so that you don't have to fetch all records. It could be also included as a function to fetch the last n entries.

…r last n hours.

- added them to the readme
@h4 h4 merged commit 364b228 into h4:master Jan 8, 2021
@53RT 53RT deleted the develop branch January 27, 2021 15:28
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants