(cls, config_dir: Optional[Path] = None)
| 306 | |
| 307 | @classmethod |
| 308 | def load(cls, config_dir: Optional[Path] = None) -> "EntityRegistry": |
| 309 | path = (Path(config_dir) / "entity_registry.json") if config_dir else cls.DEFAULT_PATH |
| 310 | if path.exists(): |
| 311 | try: |
| 312 | data = json.loads(path.read_text(encoding="utf-8")) |
| 313 | return cls(data, path) |
| 314 | except (json.JSONDecodeError, OSError): |
| 315 | pass |
| 316 | return cls(cls._empty(), path) |
| 317 | |
| 318 | def save(self): |
| 319 | self._path.parent.mkdir(parents=True, exist_ok=True) |