Hello,
This request is related to this closed issue to discuss it here, but I haven’t seen any 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.
Would it be possible to update a user’s position via the external integrations protocol? This would mean generalizing part of the integration with owntracker, I imagine. (I’m rediscovering Gladys after a break of almost 10 years if I believe my forum registration)
Another interesting addition would be to be able to update a device’s position from the protocol. This would be useful for cars (e.g.: MySkoda smart home integration, free and open source | Gladys Assistant which currently stores the position as text)