Add typed helpers and improve type hints in util/json (#88534)

* Add type hints to load_json

* Adjust ios

* Adjust nest

* Add use of load_json_array

* Add tests

* Adjust test patch

* Add test_load_json_os_error
This commit is contained in:
epenet 2023-02-22 10:09:28 +01:00 committed by GitHub
parent 906d397736
commit aa20c902db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 137 additions and 27 deletions

View file

@ -33,7 +33,7 @@ from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.util import get_random_string
from homeassistant.util.json import load_json
from homeassistant.util.json import JsonObjectType, load_json_object
from . import api
from .const import (
@ -570,7 +570,7 @@ class NestFlowHandler(
return await self.async_step_link()
flow = self.hass.data[DATA_FLOW_IMPL][DOMAIN]
tokens = await self.hass.async_add_executor_job(load_json, config_path)
tokens = await self.hass.async_add_executor_job(load_json_object, config_path)
return self._entry_from_tokens(
"Nest (import from configuration.yaml)", flow, tokens
@ -578,7 +578,7 @@ class NestFlowHandler(
@callback
def _entry_from_tokens(
self, title: str, flow: dict[str, Any], tokens: list[Any] | dict[Any, Any]
self, title: str, flow: dict[str, Any], tokens: JsonObjectType
) -> FlowResult:
"""Create an entry from tokens."""
return self.async_create_entry(