En repartant du besoin de Filtrer les scènes qui utilisent un élément précis (appareil MQTT, appareil Zigbee,...) et basé sur la suggestion de @mutmut dans Nouvelle page "Appareils" qui affichent tous les appareils de l'instance - #4 par spenceur :
Il serait utile que la nouvelle page ‹ Appareils › puisse afficher les dashboards et les scènes dans lesquels un appareil est utilisé. Cela permettrait en particulier de repérer les dashboards et scènes qu’il faudra ajuster avant de supprimer un appareil, ou de repérer un appareil qui n’est utilisé nulle part.
Je me demande si il sera suffisant de faire cela pour l’appareil (au global), ou si il faudrait distinguer les usages pour chaque fonctionnalité de l’appareil. Qu’en pensez-vous ?
Salut tout le monde !
Ce sujet est désormais en cours de développement .
Une PR a été ouverte pour lister les dashboards et scènes utilisant chaque appareil :
master ← claude/devices-usage-list
ouvert 02:54AM - 17 Aug 26 UTC
Implements feature request: https://community.gladysassistant.com/t/dans-la-page… -appareils-lister-les-dashboard-et-scene-utilisant-un-appareil/10579
### Description
On the new "Devices" page, it is now possible to see at a glance where each device is used: which dashboards display it, and which scenes reference it. This makes it easy to know what will break before deleting a device, and to spot devices that are not used anywhere.
**Open question raised in the forum topic (device-level vs per-feature usage):** this PR implements **device-level** usage. A device is considered "used" as soon as the device itself **or any of its features** is referenced by a dashboard or a scene. This keeps the list readable (one short cell per device) and answers the two use cases from the topic — "what will break if I delete this device" and "which devices are used nowhere". Per-feature granularity would fit better in a device detail view and is left out of scope.
**Server**
- New `device.getUsage(userId)` (`server/lib/device/device.getUsage.js`). It walks the dashboard `boxes` JSON and the scene `actions` / `triggers` JSON and collects every `device`, `devices`, `camera`, `device_feature` and `device_features` selector. The walk is recursive, so nested scene action blocks (`if` / `then` / `else`) are covered too. Collected feature selectors are resolved to their device.
- Exposed as a single endpoint `GET /api/v1/device/usage`, which returns the usage of **every** device in one call — the list never does one request per device. The response is an object indexed by device selector; a device missing from the response is used nowhere:
```json
{
"test-device": {
"dashboards": [{ "id": "...", "name": "Main", "selector": "main", "type": "main" }],
"scenes": [{ "id": "...", "name": "Good morning", "selector": "good-morning", "icon": "fe fe-bell" }]
}
}
```
- Dashboards are scoped exactly like `dashboard.get`: a user sees his own dashboards and the public ones. Scenes are global, as everywhere else.
**Front**
- New "Used in" column on the Devices page, listing the dashboards and the scenes as links (to `/dashboard/:selector` and `/dashboard/scene/:selector`), or "Nowhere" when the device is unused. Above 3 entries the rest is collapsed into a `+N` counter.
- New filter next to the room and integration filters: all devices / used in a dashboard or a scene / used nowhere.
- The usage is also shown on the mobile list (as plain tags, since the whole mobile row is already a link).
- New translation keys added to `en`, `fr` and `de`.
**Tests**
- `server/test/lib/device/device.getUsage.test.js`: no usage, dashboard usage (through a feature, through a direct device selector and through a camera selector), scene usage in actions (including nested `if/then/else`) and in triggers, merge of dashboards and scenes for the same device, and the dashboard visibility rule (another user's private dashboard is hidden, his public one is returned).
- `server/test/controllers/device/device.controller.test.js`: a test for the new `GET /api/v1/device/usage` route.
This pull request was produced by an automated run.
## Forum
Forum: https://community.gladysassistant.com/t/dans-la-page-appareils-lister-les-dashboard-et-scene-utilisant-un-appareil/10579
### Checklist
- [x] Tests pass: `cd server && npm run coverage` (Codecov requires 100% coverage on changed lines) and Cypress (`npm run cypress:run`) if the UI changed
- [x] Linter and prettier pass on both front and server (`npm run eslint`, `npm run prettier`)
- [x] No undocumented breaking change
---
_Generated by [Claude Code](https://claude.ai/code/session_01REGRUvErzpwtSrsi9gKh4J)_
## Summary by CodeRabbit
* **New Features**
* Added device usage information showing where devices are used in dashboards and scenes.
* Added “all,” “used,” and “not used” filters to the device list.
* Added usage details to desktop and mobile device views, including additional-use counts.
* Added localized English, German, and French labels and error messages.
* **Bug Fixes**
* Added clear error handling when device usage cannot be loaded.
* Usage filters remain unavailable until usage information finishes loading.
N’hésitez pas à suivre la PR, à tester dès que possible et à faire vos retours ici.