Pet weight: keep the decimal when writing to the API - #288
Merged
Conversation
The Pet weight number declares native_step=0.1, but the write casts the value
to int, so every fractional weight is silently discarded: setting 3.2 kg sends
{"weight": 3} and the entity reads back its previous value. For a 3-4 kg cat
that is a 5-15% error, and 0.1 kg steps are exactly the resolution a weight
trend needs.
The API accepts a float. Verified against api.eu-pet.com/latest/pet/updatepetprops
with a real account: {"weight": 3.2} returns
{'id': '101401316', 'name': 'Tea', ..., 'weight': 3.2, 'weightLabel': 'Normal',
'updatedAt': '2026-07-28T22:32:20.000+0000'}
and the value shows correctly in the PetKit app afterwards. Rounded to one
decimal to match native_step rather than passed through raw.
for more information, see https://pre-commit.ci
|
Owner
|
Hi @trunten82 |
Jezza34000
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Problem
number.<pet>_pesocannot be set to a fractional weight. The descriptor declaresnative_step=0.1, but the write casts toint:https://github.com/Jezza34000/homeassistant_petkit/blob/main/custom_components/petkit/number.py#L238
So setting 3.2 kg sends
{"weight": 3}, the entity reads back its old value, andit looks to the user as if the write silently failed. For a 3-4 kg cat that is a
5-15% error, and 0.1 kg is exactly the resolution a weight trend needs to be
useful. Present on
mainand in 1.25.0 - 1.27.0.Fix
Round to one decimal, matching
native_step, instead of truncating.Verification
Against
api.eu-pet.com/latest/pet/updatepetpropswith a real account on 1.27.0,the API accepts a float and echoes it back:
Confirmed in the PetKit app afterwards (7.1 lb with the app set to imperial,
= 3.2 kg). Three cats set to 3.3 / 3.2 / 4.3 kg, all correct.
Separate issue found while verifying, not addressed here
Worth a look independently: after a successful write the value does not appear
in Home Assistant. Every subsequent coordinator refresh kept reporting the old
weight from the account/family listing, even minutes later and after
homeassistant.update_entity, while the pet record server-side had already beenupdated. Only reloading the config entry (a fresh login) surfaced the new value.
The pet data appears to come from the account listing rather than a pet-detail
read, and that listing seems to be served stale after
updatepetprops. Happy toopen a separate issue with logs if useful.