Collar integration #8
No reviewers
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
thomas/ha-pettracer-unofficial!8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "7-collars"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR is to auto add collar devices once the initial Home Assistant integration is setup. It also adds a GPS entity, which is automatically updated on an interval.
Note to @codebot - the correct authorisation token type is Bearer. This has been tested and there are no further concerns relating to this issue.
The PR introduces collar device discovery and GPS tracking via a new
device_trackercomponent. Key observations:Security concern: The
get_collars()method usesAuthorization: Basic {token}but the token appears to be an OAuth access token (from login response), not a basic auth credential. This likely causes authentication failure—should useBearerinstead ofBasic.Hardcoded credentials in device_tracker.py: Line 7 instantiates
PetTracerAPI("", ""), which is acceptable since the token is set afterward, but could be clearer with a factory method or explicit comment.Missing error handling: No validation of
collarsresponse structure before iterating—could crash if API returns unexpected format (e.g., empty list vs null).Location accuracy = 0: Setting
location_accuracyto 0 may mislead users; consider omitting the attribute or deriving it from API data if available.Missing update mechanism: The PR description mentions GPS is "automatically updated on an interval", but no update logic (e.g.,
async_update) is implemented inPetTracker. Entities will only reflect stale data until reloaded.Minor:
API_GETCCS_EPpath normalization (lstrip('/')) is redundant givenurljoinbehavior, but harmless.Recommend addressing the auth header issue and adding update logic before merging.
Confidence: 85/100
Initial commit. More to do.to Collar integrationThe diff shows significant changes to the integration setup and API usage. Key issues:
Security vulnerability: Changed
Authorization: Basic {token}toBearer {token}— but the token type is unclear. If the API expects Basic auth (base64-encoded credentials), using Bearer will break authentication. Verify expected auth scheme.Hardcoded empty credentials:
api = PetTracerAPI("", "")ignores passed credentials; only_tokenis set later. This may cause issues if constructor validates inputs or uses defaults.Race condition in state updates:
hass.states.async_set()is called directly inside a time-interval callback without ensuring the entity exists first (e.g., device creation may lag). Could lead to errors or lost updates.Missing error handling for device creation: If
c.get('details', {}).get('name')returns None, device name becomes None — potentially invalid in HA.No cleanup logic: Missing
async_unload_entryimplementation (removed entirely), so timers and resources won’t be cleaned up on reload/uninstall.Hardcoded entity naming: Uses
device_tracker.{name}which may conflict or break with special characters/special names in collar names.Recommend verifying auth scheme, adding proper cleanup, validating collar data before use, and ensuring entities are created before updating states.
Confidence: 65/100
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.