Bonjour,
Cette demande est liée à cette issue fermée pour en discuter ici, mais je n’ai vu aucun post:
ouvert 11:20PM - 17 Oct 26 UTC
fermé 08:42AM - 23 Oct 26 UTC
claude:blocked
## Problem
An external integration cannot publish the position of a Gladys user… today (checked on core `0027571e` and `@gladysassistant/integration-sdk` 0.15.0):
- the SDK has no method for it: `getHouses()` reads the houses only (behind `location: true`), nothing about users or their location;
- the host API (`/api/integration/v1/*` in `server/api/routes.js`) has no user or location route;
- `post /api/v1/user/:user_selector/location` exists, but it takes a user session (`authenticated: true`), not the token of an integration;
- OwnTracks reaches `location.create` only through the Gladys Plus gateway (`location.handleNewGatewayOwntracksLocation.js`).
So location trackers integrated as external integrations can only publish latitude/longitude as plain device features: the user map, the areas (`user.new-location`) and the scenes based on them do not react.
The first case is [gladys-phonetrack](https://github.com/LM1LC3N7/gladys-phonetrack) (PhoneTrack, the Nextcloud app: self-hosted phone tracking), but the same need applies to any tracker (Traccar, Invoxia, car integrations with a GPS position…).
## Proposal
A minimal host route, with an explicit manifest declaration and a per-user consent:
1. `server/api/routes.js`: `'post /api/integration/v1/user/:user_selector/location'`, with `authenticated: false, externalIntegrationAuth: true`, controller `integrationHostController.publishUserLocation`.
2. `server/api/controllers/integrationHost.controller.js`: body `{ latitude, longitude, accuracy?, altitude?, created_at? }` (validated: numbers and ranges), calling a new `server/lib/external-integration/externalIntegration.publishUserLocation.js` that:
- checks a manifest declaration `user_location: true` (shown on the install screen, 403 otherwise, like `location` for the houses);
- checks that this user chose this integration as a source of their position (consent per user, for example a `users` dynamic source in `DYNAMIC_SOURCES` of `server/lib/external-integration/constants.js`, so a device can be linked to its user in the integration's configuration);
- then calls `gladys.location.create(userSelector, location)`, which already updates the user, emits `user.new-location` for the areas and the websocket event of the map.
3. `validateManifest.js`, and `docs/specs/external-integrations/contracts/host-api-endpoints.md` and `manifest.md`: the new field and route; tests next to the house ones.
4. SDK: `gladys.publishUserLocation(userSelector, { latitude, longitude, accuracy, altitude })`, and the `users` source in the fake Gladys used by integration tests.
Nothing changes for existing integrations: without `user_location: true` in the manifest, the route answers 403.
Happy to open the PR if the approach suits you.
Serait-il envisageable de pouvoir actualiser la position d’un utilisateur via le protocole des intégrations externes ? Cela reviendrait à généraliser une partie de l’intégration avec owntracker, j’imagine. (Je redécouvre Gladys après une pause de bientôt 10 ans si je crois mon inscription sur le forum)
Un autre ajout intéressant serait de pouvoir actualiser la position d’un device depuis le protocol. Cela servirait notamment pour les voitures (ex: Intégration domotique MySkoda, gratuite et open source | Gladys Assistant qui stocke en texte la position pour le moment)