From 7caddd48cd2083e26d5b3960728404519595a285 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 3 Nov 2018 10:24:02 +0100 Subject: [PATCH] Fix typos and update docstrings (#18137) --- homeassistant/components/lovelace/__init__.py | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/homeassistant/components/lovelace/__init__.py b/homeassistant/components/lovelace/__init__.py index 540fb601a90..a8cde6a2b93 100644 --- a/homeassistant/components/lovelace/__init__.py +++ b/homeassistant/components/lovelace/__init__.py @@ -1,16 +1,22 @@ -"""Lovelace UI.""" -import logging -import uuid +""" +Support for the Lovelace UI. + +For more details about this component, please refer to the documentation +at https://www.home-assistant.io/lovelace/ +""" from functools import wraps +import logging from typing import Dict, List, Union +import uuid import voluptuous as vol -import homeassistant.util.ruamel_yaml as yaml from homeassistant.components import websocket_api from homeassistant.exceptions import HomeAssistantError +import homeassistant.util.ruamel_yaml as yaml _LOGGER = logging.getLogger(__name__) + DOMAIN = 'lovelace' LOVELACE_CONFIG_FILE = 'ui-lovelace.yaml' @@ -36,8 +42,8 @@ WS_TYPE_MOVE_VIEW = 'lovelace/config/view/move' WS_TYPE_DELETE_VIEW = 'lovelace/config/view/delete' SCHEMA_GET_LOVELACE_UI = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ - vol.Required('type'): vol.Any(WS_TYPE_GET_LOVELACE_UI, - OLD_WS_TYPE_GET_LOVELACE_UI), + vol.Required('type'): + vol.Any(WS_TYPE_GET_LOVELACE_UI, OLD_WS_TYPE_GET_LOVELACE_UI), }) SCHEMA_MIGRATE_CONFIG = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ @@ -47,16 +53,16 @@ SCHEMA_MIGRATE_CONFIG = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ SCHEMA_GET_CARD = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ vol.Required('type'): WS_TYPE_GET_CARD, vol.Required('card_id'): str, - vol.Optional('format', default=FORMAT_YAML): vol.Any(FORMAT_JSON, - FORMAT_YAML), + vol.Optional('format', default=FORMAT_YAML): + vol.Any(FORMAT_JSON, FORMAT_YAML), }) SCHEMA_UPDATE_CARD = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ vol.Required('type'): WS_TYPE_UPDATE_CARD, vol.Required('card_id'): str, vol.Required('card_config'): vol.Any(str, Dict), - vol.Optional('format', default=FORMAT_YAML): vol.Any(FORMAT_JSON, - FORMAT_YAML), + vol.Optional('format', default=FORMAT_YAML): + vol.Any(FORMAT_JSON, FORMAT_YAML), }) SCHEMA_ADD_CARD = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ @@ -64,8 +70,8 @@ SCHEMA_ADD_CARD = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ vol.Required('view_id'): str, vol.Required('card_config'): vol.Any(str, Dict), vol.Optional('position'): int, - vol.Optional('format', default=FORMAT_YAML): vol.Any(FORMAT_JSON, - FORMAT_YAML), + vol.Optional('format', default=FORMAT_YAML): + vol.Any(FORMAT_JSON, FORMAT_YAML), }) SCHEMA_MOVE_CARD = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({ @@ -143,12 +149,12 @@ def migrate_config(fname: str) -> None: view_id = str(view.get('id', '')) if not view_id: updated = True - view.insert(0, 'id', index, - comment="Automatically created id") + view.insert(0, 'id', index, comment="Automatically created id") else: if view_id in seen_view_ids: raise DuplicateIdError( - 'ID `{}` has multiple occurances in views'.format(view_id)) + 'ID `{}` has multiple occurrences in views'.format( + view_id)) seen_view_ids.add(view_id) for card in view.get('cards', []): card_id = str(card.get('id', '')) @@ -159,7 +165,7 @@ def migrate_config(fname: str) -> None: else: if card_id in seen_card_ids: raise DuplicateIdError( - 'ID `{}` has multiple occurances in cards' + 'ID `{}` has multiple occurrences in cards' .format(card_id)) seen_card_ids.add(card_id) index += 1 @@ -229,8 +235,8 @@ def add_card(fname: str, view_id: str, card_config: str, def move_card(fname: str, card_id: str, position: int = None) -> None: """Move a card to a different position.""" if position is None: - raise HomeAssistantError('Position is required if view is not\ - specified.') + raise HomeAssistantError( + 'Position is required if view is not specified.') config = yaml.load_yaml(fname, True) for view in config.get('views', []): for card in view.get('cards', []): @@ -386,40 +392,34 @@ async def async_setup(hass, config): SCHEMA_GET_LOVELACE_UI) hass.components.websocket_api.async_register_command( - WS_TYPE_GET_CARD, websocket_lovelace_get_card, - SCHEMA_GET_CARD) + WS_TYPE_GET_CARD, websocket_lovelace_get_card, SCHEMA_GET_CARD) hass.components.websocket_api.async_register_command( WS_TYPE_UPDATE_CARD, websocket_lovelace_update_card, SCHEMA_UPDATE_CARD) hass.components.websocket_api.async_register_command( - WS_TYPE_ADD_CARD, websocket_lovelace_add_card, - SCHEMA_ADD_CARD) + WS_TYPE_ADD_CARD, websocket_lovelace_add_card, SCHEMA_ADD_CARD) hass.components.websocket_api.async_register_command( - WS_TYPE_MOVE_CARD, websocket_lovelace_move_card, - SCHEMA_MOVE_CARD) + WS_TYPE_MOVE_CARD, websocket_lovelace_move_card, SCHEMA_MOVE_CARD) hass.components.websocket_api.async_register_command( WS_TYPE_DELETE_CARD, websocket_lovelace_delete_card, SCHEMA_DELETE_CARD) hass.components.websocket_api.async_register_command( - WS_TYPE_GET_VIEW, websocket_lovelace_get_view, - SCHEMA_GET_VIEW) + WS_TYPE_GET_VIEW, websocket_lovelace_get_view, SCHEMA_GET_VIEW) hass.components.websocket_api.async_register_command( WS_TYPE_UPDATE_VIEW, websocket_lovelace_update_view, SCHEMA_UPDATE_VIEW) hass.components.websocket_api.async_register_command( - WS_TYPE_ADD_VIEW, websocket_lovelace_add_view, - SCHEMA_ADD_VIEW) + WS_TYPE_ADD_VIEW, websocket_lovelace_add_view, SCHEMA_ADD_VIEW) hass.components.websocket_api.async_register_command( - WS_TYPE_MOVE_VIEW, websocket_lovelace_move_view, - SCHEMA_MOVE_VIEW) + WS_TYPE_MOVE_VIEW, websocket_lovelace_move_view, SCHEMA_MOVE_VIEW) hass.components.websocket_api.async_register_command( WS_TYPE_DELETE_VIEW, websocket_lovelace_delete_view, @@ -429,7 +429,7 @@ async def async_setup(hass, config): def handle_yaml_errors(func): - """Handle error with websocket calls.""" + """Handle error with WebSocket calls.""" @wraps(func) async def send_with_error_handling(hass, connection, msg): error = None @@ -463,7 +463,7 @@ def handle_yaml_errors(func): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_config(hass, connection, msg): - """Send lovelace UI config over websocket config.""" + """Send Lovelace UI config over WebSocket configuration.""" return await hass.async_add_executor_job( load_config, hass.config.path(LOVELACE_CONFIG_FILE)) @@ -471,7 +471,7 @@ async def websocket_lovelace_config(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_migrate_config(hass, connection, msg): - """Migrate lovelace UI config.""" + """Migrate Lovelace UI configuration.""" return await hass.async_add_executor_job( migrate_config, hass.config.path(LOVELACE_CONFIG_FILE)) @@ -479,7 +479,7 @@ async def websocket_lovelace_migrate_config(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_get_card(hass, connection, msg): - """Send lovelace card config over websocket config.""" + """Send Lovelace card config over WebSocket configuration.""" return await hass.async_add_executor_job( get_card, hass.config.path(LOVELACE_CONFIG_FILE), msg['card_id'], msg.get('format', FORMAT_YAML)) @@ -488,7 +488,7 @@ async def websocket_lovelace_get_card(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_update_card(hass, connection, msg): - """Receive lovelace card config over websocket and save.""" + """Receive Lovelace card configuration over WebSocket and save.""" return await hass.async_add_executor_job( update_card, hass.config.path(LOVELACE_CONFIG_FILE), msg['card_id'], msg['card_config'], msg.get('format', FORMAT_YAML)) @@ -497,7 +497,7 @@ async def websocket_lovelace_update_card(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_add_card(hass, connection, msg): - """Add new card to view over websocket and save.""" + """Add new card to view over WebSocket and save.""" return await hass.async_add_executor_job( add_card, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_id'], msg['card_config'], msg.get('position'), @@ -507,7 +507,7 @@ async def websocket_lovelace_add_card(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_move_card(hass, connection, msg): - """Move card to different position over websocket and save.""" + """Move card to different position over WebSocket and save.""" if 'new_view_id' in msg: return await hass.async_add_executor_job( move_card_view, hass.config.path(LOVELACE_CONFIG_FILE), @@ -521,16 +521,15 @@ async def websocket_lovelace_move_card(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_delete_card(hass, connection, msg): - """Delete card from lovelace over websocket and save.""" + """Delete card from Lovelace over WebSocket and save.""" return await hass.async_add_executor_job( - delete_card, hass.config.path(LOVELACE_CONFIG_FILE), - msg['card_id']) + delete_card, hass.config.path(LOVELACE_CONFIG_FILE), msg['card_id']) @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_get_view(hass, connection, msg): - """Send lovelace view config over websocket config.""" + """Send Lovelace view config over WebSocket config.""" return await hass.async_add_executor_job( get_view, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_id'], msg.get('format', FORMAT_YAML)) @@ -539,7 +538,7 @@ async def websocket_lovelace_get_view(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_update_view(hass, connection, msg): - """Receive lovelace card config over websocket and save.""" + """Receive Lovelace card config over WebSocket and save.""" return await hass.async_add_executor_job( update_view, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_id'], msg['view_config'], msg.get('format', FORMAT_YAML)) @@ -548,7 +547,7 @@ async def websocket_lovelace_update_view(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_add_view(hass, connection, msg): - """Add new view over websocket and save.""" + """Add new view over WebSocket and save.""" return await hass.async_add_executor_job( add_view, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_config'], msg.get('position'), @@ -558,7 +557,7 @@ async def websocket_lovelace_add_view(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_move_view(hass, connection, msg): - """Move view to different position over websocket and save.""" + """Move view to different position over WebSocket and save.""" return await hass.async_add_executor_job( move_view, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_id'], msg['new_position']) @@ -567,7 +566,6 @@ async def websocket_lovelace_move_view(hass, connection, msg): @websocket_api.async_response @handle_yaml_errors async def websocket_lovelace_delete_view(hass, connection, msg): - """Delete card from lovelace over websocket and save.""" + """Delete card from Lovelace over WebSocket and save.""" return await hass.async_add_executor_job( - delete_view, hass.config.path(LOVELACE_CONFIG_FILE), - msg['view_id']) + delete_view, hass.config.path(LOVELACE_CONFIG_FILE), msg['view_id'])