Converted shopping list to use json util and added default override for json util (#12478)
* Converted shopping list to use json util, Added default override for json util * Reverted accidental revert * Fixed pylint issue
This commit is contained in:
parent
635d36c6ba
commit
60148f3e83
2 changed files with 8 additions and 12 deletions
|
@ -8,8 +8,11 @@ from homeassistant.exceptions import HomeAssistantError
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_UNDEFINED = object()
|
||||
|
||||
def load_json(filename: str) -> Union[List, Dict]:
|
||||
|
||||
def load_json(filename: str, default: Union[List, Dict] = _UNDEFINED) \
|
||||
-> Union[List, Dict]:
|
||||
"""Load JSON data from a file and return as dict or list.
|
||||
|
||||
Defaults to returning empty dict if file is not found.
|
||||
|
@ -26,7 +29,7 @@ def load_json(filename: str) -> Union[List, Dict]:
|
|||
except OSError as error:
|
||||
_LOGGER.exception('JSON file reading failed: %s', filename)
|
||||
raise HomeAssistantError(error)
|
||||
return {} # (also evaluates to False)
|
||||
return {} if default is _UNDEFINED else default
|
||||
|
||||
|
||||
def save_json(filename: str, config: Union[List, Dict]):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue