Add JSON support to load_fixture (#88076)
* Add JSON support to load_fixture * More tests * Remove lru_cache on load_json
This commit is contained in:
parent
bc2b35765e
commit
8c821c8969
9 changed files with 104 additions and 34 deletions
|
@ -67,6 +67,14 @@ from homeassistant.helpers.typing import ConfigType, StateType
|
|||
from homeassistant.setup import setup_component
|
||||
from homeassistant.util.async_ import run_callback_threadsafe
|
||||
import homeassistant.util.dt as date_util
|
||||
from homeassistant.util.json import (
|
||||
JsonArrayType,
|
||||
JsonObjectType,
|
||||
JsonValueType,
|
||||
json_loads,
|
||||
json_loads_array,
|
||||
json_loads_object,
|
||||
)
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
import homeassistant.util.uuid as uuid_util
|
||||
import homeassistant.util.yaml.loader as yaml_loader
|
||||
|
@ -428,6 +436,27 @@ def load_fixture(filename: str, integration: str | None = None) -> str:
|
|||
return get_fixture_path(filename, integration).read_text()
|
||||
|
||||
|
||||
def load_json_value_fixture(
|
||||
filename: str, integration: str | None = None
|
||||
) -> JsonValueType:
|
||||
"""Load a JSON value from a fixture."""
|
||||
return json_loads(load_fixture(filename, integration))
|
||||
|
||||
|
||||
def load_json_array_fixture(
|
||||
filename: str, integration: str | None = None
|
||||
) -> JsonArrayType:
|
||||
"""Load a JSON array from a fixture."""
|
||||
return json_loads_array(load_fixture(filename, integration))
|
||||
|
||||
|
||||
def load_json_object_fixture(
|
||||
filename: str, integration: str | None = None
|
||||
) -> JsonObjectType:
|
||||
"""Load a JSON object from a fixture."""
|
||||
return json_loads_object(load_fixture(filename, integration))
|
||||
|
||||
|
||||
def mock_state_change_event(
|
||||
hass: HomeAssistant, new_state: State, old_state: State | None = None
|
||||
) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue