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:
Frederik Bolding 2018-02-18 22:11:24 +01:00 committed by Paulus Schoutsen
parent 635d36c6ba
commit 60148f3e83
2 changed files with 8 additions and 12 deletions

View file

@ -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]):