Introduce ServerUserAvatarRepository#6989
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new ServerUserAvatarManager utility intended to load the current user’s avatar for a given Home Assistant server by locating the linked person entity, downloading the entity_picture via Coil with authentication, and leveraging Coil caching to avoid repeat downloads.
Changes:
- Added
ServerUserAvatarManagerfor avatar lookup/download + cache fallback behavior - Introduced
PERSON_DOMAINconstant and replaced hardcoded"person"usage inEntityutilities - Added
Entity.isPersonOf(userId)helper and unit tests covering the manager’s behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/IntegrationDomains.kt | Adds PERSON_DOMAIN constant for consistent domain usage |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/integration/Entity.kt | Switches to PERSON_DOMAIN and adds isPersonOf(userId) helper |
| app/src/main/kotlin/io/homeassistant/companion/android/util/ServerUserAvatarManager.kt | New manager to resolve/download user avatar and read from Coil caches |
| app/src/test/kotlin/io/homeassistant/companion/android/util/ServerUserAvatarManagerTest.kt | Adds unit coverage for avatar resolution, caching keys, and request properties |
|
I think this raises some architecture questions, sorry
|
I renamed it from Manager to Repository because in the next PR that uses it I've introduced a |
|
Naming aside, the code here looks good.
I don't follow this logic. The code in this PR looks like a use case to me; the |
Summary
This PR introduce a new manager
ServerUserAvatarRepositorythat is not yet use in this PR. This repository contains the logic to retrieve the Avatar image from core for a given server. We ensure to also cache the image whenever we can to avoid downloading it multiple times.Checklist
Any other notes
If the server is not available it doesn't return anything because we need the list of entities to get the cache key. We cannot enumerate the disk cache because the key is transformed to a sha256 so looking at the
filesystemattribute of thefileLoaderwon't help us to find the cache without knowing the full cache key.This doesn't leave in :common because it rely on coil.