1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 15:22:24 +01:00

Support ignoring discovered devices from the dashboard (#7665)

This commit is contained in:
Jesse Hills
2024-10-25 07:55:14 +13:00
committed by GitHub
parent 5b5c2fe71b
commit ca5c73d170
3 changed files with 71 additions and 0 deletions

View File

@@ -541,6 +541,46 @@ class ImportRequestHandler(BaseHandler):
self.finish()
class IgnoreDeviceRequestHandler(BaseHandler):
@authenticated
def post(self) -> None:
dashboard = DASHBOARD
try:
args = json.loads(self.request.body.decode())
device_name = args["name"]
ignore = args["ignore"]
except (json.JSONDecodeError, KeyError):
self.set_status(400)
self.set_header("content-type", "application/json")
self.write(json.dumps({"error": "Invalid payload"}))
return
ignored_device = next(
(
res
for res in dashboard.import_result.values()
if res.device_name == device_name
),
None,
)
if ignored_device is None:
self.set_status(404)
self.set_header("content-type", "application/json")
self.write(json.dumps({"error": "Device not found"}))
return
if ignore:
dashboard.ignored_devices.add(ignored_device.device_name)
else:
dashboard.ignored_devices.discard(ignored_device.device_name)
dashboard.save_ignored_devices()
self.set_status(204)
self.finish()
class DownloadListRequestHandler(BaseHandler):
@authenticated
@bind_config
@@ -688,6 +728,7 @@ class ListDevicesHandler(BaseHandler):
"project_name": res.project_name,
"project_version": res.project_version,
"network": res.network,
"ignored": res.device_name in dashboard.ignored_devices,
}
for res in dashboard.import_result.values()
if res.device_name not in configured
@@ -1156,6 +1197,7 @@ def make_app(debug=get_bool_env(ENV_DEV)) -> tornado.web.Application:
(f"{rel}prometheus-sd", PrometheusServiceDiscoveryHandler),
(f"{rel}boards/([a-z0-9]+)", BoardsRequestHandler),
(f"{rel}version", EsphomeVersionHandler),
(f"{rel}ignore-device", IgnoreDeviceRequestHandler),
],
**app_settings,
)