|
#!/usr/bin/env python |
|
|
|
import json |
|
import re |
|
|
|
entity_registry_file = open("core.entity_registry", "r+") |
|
entity_registry = json.load(entity_registry_file) |
|
|
|
device_registry_file = open("core.device_registry", "r+") |
|
device_registry = json.load(device_registry_file) |
|
|
|
config_registry_file = open("core.config_entries", "r+") |
|
config_registry = json.load(config_registry_file) |
|
|
|
hidden_entity_ids = [] |
|
hidden_device_ids = [] |
|
|
|
camera_entries = {} |
|
|
|
for config_registry in config_registry["data"]["entries"]: |
|
hidden_entity_ids = hidden_entity_ids + config_registry.get("options", {}).get("entities", []) |
|
if "192.168.20.180" in config_registry.get("options", {}).get("still_image_url", ""): |
|
camera_entries[config_registry["entry_id"]] = config_registry |
|
|
|
for device in device_registry["data"]["devices"]: |
|
if "LB02-5W-GU10-TAS" == device.get("model",""): |
|
hidden_device_ids.append(device["id"]) |
|
|
|
for device in device_registry["data"]["devices"]: |
|
if "LB02-5W-GU10-TAS" == device.get("model",""): |
|
hidden_device_ids.append(device["id"]) |
|
|
|
for entity in entity_registry["data"]["entities"]: |
|
name = entity.get("entity_id", "").lower().replace(" ", "_") |
|
entity["hidden_by"] = None |
|
if "live_feed" in name: |
|
hidden_device_ids.append(entity["device_id"]) |
|
|
|
for entity in entity_registry["data"]["entities"]: |
|
if entity["entity_id"] in ["dining_light"]: |
|
entity["hidden_by"] = None |
|
continue |
|
|
|
if entity["config_entry_id"] in camera_entries: |
|
entry_id = camera_entries.get(entity["config_entry_id"], {}).get("title").lower() |
|
entity['entity_id'] = f"camera.{entry_id}" |
|
|
|
if entity['entity_id'] in hidden_entity_ids: |
|
entity["hidden_by"] = "user" |
|
|
|
if entity["device_id"] in hidden_device_ids and not entity["entity_id"].startswith("light."): |
|
print(f"hiding {entity['entity_id']} as it matches a hidden device id") |
|
entity["hidden_by"] = "user" |
|
if "media_player" in entity.get("entity_id") and "android" not in entity.get("entity_id"): |
|
print(f"hiding {entity.get('entity_id')}") |
|
entity["hidden_by"] = "user" |
|
if "Room" in entity.get("model", ""): |
|
entity["hidden_by"] = "user" |
|
if "frigate" in entity["platform"]: |
|
entity["hidden_by"] = "user" |
|
if not entity["entity_id"].endswith("_frigate"): |
|
entity["entity_id"] = entity["entity_id"] + "_frigate" |
|
|
|
if entity.get("original_name") and "Wiser " in entity.get("original_name", ""): |
|
entity["name"] = entity.get("original_name", "").replace("Wiser ", "") |
|
entity["has_entity_name"] = True |
|
if entity.get("original_name") and "Wiser " in entity.get("original_name", "") and "climate" in entity["entity_id"]: |
|
entity["name"] = entity["name"] + " thermostat" |
|
if "wiser" in entity["entity_id"] and "climate" not in entity["entity_id"] and "button.wiser_toggle_hot_water" not in entity["entity_id"]: |
|
entity["hidden_by"] = "user" |
|
if "wled" == entity["platform"] and not entity["entity_id"].startswith("light"): |
|
entity["hidden_by"] = "user" |
|
if "doorbell" in entity["entity_id"] and "camera" not in entity["entity_id"]: |
|
entity["hidden_by"] = "user" |
|
|
|
if len(re.findall(r'_[0-9]$', entity["entity_id"])) > 0: |
|
entity["hidden_by"] = "user" |
|
|
|
for keyword in ["camera.s5_map", "valetudo_s5_map_data", "select.", "camera.rockrobo_map", "valetudo_s7_map_data", "breakfast_bar", "sensor", "script", "automation", "button", "update", "person", "shellyem", "window_detection", "itrv", "smoke_alarm"]: |
|
if keyword in entity["entity_id"]: |
|
entity["hidden_by"] = "user" |
|
|
|
entity_registry_file.seek(0) |
|
entity_registry_file.write(json.dumps(entity_registry, indent=4)) |
|
entity_registry_file.truncate() |