mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Force refresh Lovelace (#19073)
* Force refresh Lovelace * Check config on load * Update __init__.py * Update __init__.py
This commit is contained in:
parent
0a3af545fe
commit
455508deac
@ -48,6 +48,7 @@ WS_TYPE_DELETE_VIEW = 'lovelace/config/view/delete'
|
|||||||
SCHEMA_GET_LOVELACE_UI = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
SCHEMA_GET_LOVELACE_UI = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||||
vol.Required('type'):
|
vol.Required('type'):
|
||||||
vol.Any(WS_TYPE_GET_LOVELACE_UI, OLD_WS_TYPE_GET_LOVELACE_UI),
|
vol.Any(WS_TYPE_GET_LOVELACE_UI, OLD_WS_TYPE_GET_LOVELACE_UI),
|
||||||
|
vol.Optional('force', default=False): bool,
|
||||||
})
|
})
|
||||||
|
|
||||||
SCHEMA_MIGRATE_CONFIG = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
SCHEMA_MIGRATE_CONFIG = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||||
@ -144,12 +145,12 @@ class DuplicateIdError(HomeAssistantError):
|
|||||||
"""Duplicate ID's."""
|
"""Duplicate ID's."""
|
||||||
|
|
||||||
|
|
||||||
def load_config(hass) -> JSON_TYPE:
|
def load_config(hass, force: bool) -> JSON_TYPE:
|
||||||
"""Load a YAML file."""
|
"""Load a YAML file."""
|
||||||
fname = hass.config.path(LOVELACE_CONFIG_FILE)
|
fname = hass.config.path(LOVELACE_CONFIG_FILE)
|
||||||
|
|
||||||
# Check for a cached version of the config
|
# Check for a cached version of the config
|
||||||
if LOVELACE_DATA in hass.data:
|
if not force and LOVELACE_DATA in hass.data:
|
||||||
config, last_update = hass.data[LOVELACE_DATA]
|
config, last_update = hass.data[LOVELACE_DATA]
|
||||||
modtime = os.path.getmtime(fname)
|
modtime = os.path.getmtime(fname)
|
||||||
if config and last_update > modtime:
|
if config and last_update > modtime:
|
||||||
@ -158,23 +159,29 @@ def load_config(hass) -> JSON_TYPE:
|
|||||||
config = yaml.load_yaml(fname, False)
|
config = yaml.load_yaml(fname, False)
|
||||||
seen_card_ids = set()
|
seen_card_ids = set()
|
||||||
seen_view_ids = set()
|
seen_view_ids = set()
|
||||||
|
if 'views' in config and not isinstance(config['views'], list):
|
||||||
|
raise HomeAssistantError("Views should be a list.")
|
||||||
for view in config.get('views', []):
|
for view in config.get('views', []):
|
||||||
view_id = view.get('id')
|
if 'id' in view and not isinstance(view['id'], (str, int)):
|
||||||
if view_id:
|
raise HomeAssistantError(
|
||||||
view_id = str(view_id)
|
"Your config contains view(s) with invalid ID(s).")
|
||||||
if view_id in seen_view_ids:
|
view_id = str(view.get('id', ''))
|
||||||
raise DuplicateIdError(
|
if view_id in seen_view_ids:
|
||||||
'ID `{}` has multiple occurances in views'.format(view_id))
|
raise DuplicateIdError(
|
||||||
seen_view_ids.add(view_id)
|
'ID `{}` has multiple occurances in views'.format(view_id))
|
||||||
|
seen_view_ids.add(view_id)
|
||||||
|
if 'cards' in view and not isinstance(view['cards'], list):
|
||||||
|
raise HomeAssistantError("Cards should be a list.")
|
||||||
for card in view.get('cards', []):
|
for card in view.get('cards', []):
|
||||||
card_id = card.get('id')
|
if 'id' in card and not isinstance(card['id'], (str, int)):
|
||||||
if card_id:
|
raise HomeAssistantError(
|
||||||
card_id = str(card_id)
|
"Your config contains card(s) with invalid ID(s).")
|
||||||
if card_id in seen_card_ids:
|
card_id = str(card.get('id', ''))
|
||||||
raise DuplicateIdError(
|
if card_id in seen_card_ids:
|
||||||
'ID `{}` has multiple occurances in cards'
|
raise DuplicateIdError(
|
||||||
.format(card_id))
|
'ID `{}` has multiple occurances in cards'
|
||||||
seen_card_ids.add(card_id)
|
.format(card_id))
|
||||||
|
seen_card_ids.add(card_id)
|
||||||
hass.data[LOVELACE_DATA] = (config, time.time())
|
hass.data[LOVELACE_DATA] = (config, time.time())
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@ -539,7 +546,8 @@ def handle_yaml_errors(func):
|
|||||||
@handle_yaml_errors
|
@handle_yaml_errors
|
||||||
async def websocket_lovelace_config(hass, connection, msg):
|
async def websocket_lovelace_config(hass, connection, msg):
|
||||||
"""Send Lovelace UI config over WebSocket configuration."""
|
"""Send Lovelace UI config over WebSocket configuration."""
|
||||||
return await hass.async_add_executor_job(load_config, hass)
|
return await hass.async_add_executor_job(load_config, hass,
|
||||||
|
msg.get('force', False))
|
||||||
|
|
||||||
|
|
||||||
@websocket_api.async_response
|
@websocket_api.async_response
|
||||||
|
Loading…
x
Reference in New Issue
Block a user