Initil after Upgrade
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from functools import partial
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
@@ -101,12 +102,9 @@ class LocalLoader(Loader):
|
||||
_model = model.lower()
|
||||
|
||||
if self._is_custom_directory:
|
||||
model_path = os.path.join(self._data_directory)
|
||||
model_json_path = os.path.join(model_path, "model.json")
|
||||
if not os.path.exists(model_json_path):
|
||||
raise LibraryLoadingError(f"model.json not found for manufacturer {_manufacturer} " + f"and model {_model} in path {model_json_path}")
|
||||
|
||||
model_json = await self._hass.async_add_executor_job(self._load_json, model_json_path)
|
||||
model_path, model_json = await self._hass.async_add_executor_job(
|
||||
partial(self._load_custom_model, _manufacturer, _model),
|
||||
)
|
||||
return model_json, model_path
|
||||
|
||||
lib_models = self._manufacturer_model_listing.get(_manufacturer)
|
||||
@@ -205,6 +203,17 @@ class LocalLoader(Loader):
|
||||
|
||||
self._manufacturer_model_listing[manufacturer].update({search_key: profile})
|
||||
|
||||
def _load_custom_model(self, manufacturer: str, model: str) -> tuple[str, dict[str, Any]]:
|
||||
"""Load model.json from a directly configured custom model directory."""
|
||||
model_path = os.path.join(self._data_directory)
|
||||
model_json_path = os.path.join(model_path, "model.json")
|
||||
if not os.path.exists(model_json_path):
|
||||
raise LibraryLoadingError(
|
||||
f"model.json not found for manufacturer {manufacturer} and model {model} in path {model_json_path}",
|
||||
)
|
||||
|
||||
return model_path, self._load_json(model_json_path)
|
||||
|
||||
def _load_json(self, model_json_path: str) -> dict[str, Any]:
|
||||
"""Load model.json file for a given model."""
|
||||
with open(model_json_path) as file:
|
||||
|
||||
Reference in New Issue
Block a user