History Data for last n records #28
Merged
+44
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 recenthistory_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 thehistory_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.