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:
1 parent
635d36c6ba
commit
60148f3e83
2 files changed
+8
-12
No files matched your search
@@ -1,8 +1,6 @@
|
||||
"""Component to manage a shopping list."""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import voluptuous as vol
|
||||
@@ -14,7 +12,7 @@ from homeassistant.components.http.data_validator import (
|
||||
RequestDataValidator)
|
||||
from homeassistant.helpers import intent
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from homeassistant.util.json import load_json, save_json
|
||||
|
||||
DOMAIN = 'shopping_list'
|
||||
DEPENDENCIES = ['http']
|
||||
@@ -101,18 +99,13 @@ class ShoppingData:
|
||||
"""Load items."""
|
||||
def load():
|
||||
"""Load the items synchronously."""
|
||||
path = self.hass.config.path(PERSISTENCE)
|
||||
if not os.path.isfile(path):
|
||||
return []
|
||||
with open(path) as file:
|
||||
return json.loads(file.read())
|
||||
return load_json(self.hass.config.path(PERSISTENCE), default=[])
|
||||
|
||||
self.items = yield from self.hass.async_add_job(load)
|
||||
|
||||
def save(self):
|
||||
"""Save the items."""
|
||||
with open(self.hass.config.path(PERSISTENCE), 'wt') as file:
|
||||
file.write(json.dumps(self.items, sort_keys=True, indent=4))
|
||||
save_json(self.hass.config.path(PERSISTENCE), self.items)
|
||||
|
||||
|
||||
class AddItemIntent(intent.IntentHandler):
|
||||
|
||||
Reference in new issue
Block a user