Use core constants for helpers (#46240)

pull/46262/head
tkdrob 2021-02-08 16:53:17 -05:00 committed by GitHub
parent 00bbf8c3a2
commit c2302784c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1 additions and 18 deletions

View File

@ -136,7 +136,6 @@ class YamlCollection(ObservableCollection):
async def async_load(self, data: List[dict]) -> None: async def async_load(self, data: List[dict]) -> None:
"""Load the YAML collection. Overrides existing data.""" """Load the YAML collection. Overrides existing data."""
old_ids = set(self.data) old_ids = set(self.data)
change_sets = [] change_sets = []

View File

@ -549,7 +549,6 @@ unit_system = vol.All(
def template(value: Optional[Any]) -> template_helper.Template: def template(value: Optional[Any]) -> template_helper.Template:
"""Validate a jinja2 template.""" """Validate a jinja2 template."""
if value is None: if value is None:
raise vol.Invalid("template value is None") raise vol.Invalid("template value is None")
if isinstance(value, (list, dict, template_helper.Template)): if isinstance(value, (list, dict, template_helper.Template)):
@ -566,7 +565,6 @@ def template(value: Optional[Any]) -> template_helper.Template:
def dynamic_template(value: Optional[Any]) -> template_helper.Template: def dynamic_template(value: Optional[Any]) -> template_helper.Template:
"""Validate a dynamic (non static) jinja2 template.""" """Validate a dynamic (non static) jinja2 template."""
if value is None: if value is None:
raise vol.Invalid("template value is None") raise vol.Invalid("template value is None")
if isinstance(value, (list, dict, template_helper.Template)): if isinstance(value, (list, dict, template_helper.Template)):

View File

@ -65,7 +65,6 @@ def async_generate_entity_id(
hass: Optional[HomeAssistant] = None, hass: Optional[HomeAssistant] = None,
) -> str: ) -> str:
"""Generate a unique entity ID based on given entity IDs or used IDs.""" """Generate a unique entity ID based on given entity IDs or used IDs."""
name = (name or DEVICE_DEFAULT_NAME).lower() name = (name or DEVICE_DEFAULT_NAME).lower()
preferred_string = entity_id_format.format(slugify(name)) preferred_string = entity_id_format.format(slugify(name))

View File

@ -299,7 +299,6 @@ def _async_remove_indexed_listeners(
job: HassJob, job: HassJob,
) -> None: ) -> None:
"""Remove a listener.""" """Remove a listener."""
callbacks = hass.data[data_key] callbacks = hass.data[data_key]
for storage_key in storage_keys: for storage_key in storage_keys:
@ -686,7 +685,6 @@ def async_track_template(
Callable to unregister the listener. Callable to unregister the listener.
""" """
job = HassJob(action) job = HassJob(action)
@callback @callback
@ -1105,7 +1103,6 @@ def async_track_point_in_time(
point_in_time: datetime, point_in_time: datetime,
) -> CALLBACK_TYPE: ) -> CALLBACK_TYPE:
"""Add a listener that fires once after a specific point in time.""" """Add a listener that fires once after a specific point in time."""
job = action if isinstance(action, HassJob) else HassJob(action) job = action if isinstance(action, HassJob) else HassJob(action)
@callback @callback
@ -1329,7 +1326,6 @@ def async_track_utc_time_change(
local: bool = False, local: bool = False,
) -> CALLBACK_TYPE: ) -> CALLBACK_TYPE:
"""Add a listener that will fire if time matches a pattern.""" """Add a listener that will fire if time matches a pattern."""
job = HassJob(action) job = HassJob(action)
# We do not have to wrap the function with time pattern matching logic # We do not have to wrap the function with time pattern matching logic
# if no pattern given # if no pattern given

View File

@ -70,7 +70,6 @@ def report_integration(
Async friendly. Async friendly.
""" """
found_frame, integration, path = integration_frame found_frame, integration, path = integration_frame
index = found_frame.filename.index(path) index = found_frame.filename.index(path)

View File

@ -51,7 +51,6 @@ def create_async_httpx_client(
This method must be run in the event loop. This method must be run in the event loop.
""" """
client = httpx.AsyncClient( client = httpx.AsyncClient(
verify=verify_ssl, verify=verify_ssl,
headers={USER_AGENT: SERVER_SOFTWARE}, headers={USER_AGENT: SERVER_SOFTWARE},

View File

@ -157,13 +157,11 @@ async def async_setup_reload_service(
hass: HomeAssistantType, domain: str, platforms: Iterable hass: HomeAssistantType, domain: str, platforms: Iterable
) -> None: ) -> None:
"""Create the reload service for the domain.""" """Create the reload service for the domain."""
if hass.services.has_service(domain, SERVICE_RELOAD): if hass.services.has_service(domain, SERVICE_RELOAD):
return return
async def _reload_config(call: Event) -> None: async def _reload_config(call: Event) -> None:
"""Reload the platforms.""" """Reload the platforms."""
await async_reload_integration_platforms(hass, domain, platforms) await async_reload_integration_platforms(hass, domain, platforms)
hass.bus.async_fire(f"event_{domain}_reloaded", context=call.context) hass.bus.async_fire(f"event_{domain}_reloaded", context=call.context)
@ -176,7 +174,6 @@ def setup_reload_service(
hass: HomeAssistantType, domain: str, platforms: Iterable hass: HomeAssistantType, domain: str, platforms: Iterable
) -> None: ) -> None:
"""Sync version of async_setup_reload_service.""" """Sync version of async_setup_reload_service."""
asyncio.run_coroutine_threadsafe( asyncio.run_coroutine_threadsafe(
async_setup_reload_service(hass, domain, platforms), async_setup_reload_service(hass, domain, platforms),
hass.loop, hass.loop,

View File

@ -26,6 +26,7 @@ from homeassistant.const import (
ATTR_DEVICE_ID, ATTR_DEVICE_ID,
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
CONF_SERVICE, CONF_SERVICE,
CONF_SERVICE_DATA,
CONF_SERVICE_TEMPLATE, CONF_SERVICE_TEMPLATE,
CONF_TARGET, CONF_TARGET,
ENTITY_MATCH_ALL, ENTITY_MATCH_ALL,
@ -62,7 +63,6 @@ if TYPE_CHECKING:
CONF_SERVICE_ENTITY_ID = "entity_id" CONF_SERVICE_ENTITY_ID = "entity_id"
CONF_SERVICE_DATA = "data"
CONF_SERVICE_DATA_TEMPLATE = "data_template" CONF_SERVICE_DATA_TEMPLATE = "data_template"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -202,7 +202,6 @@ class Store:
async def _async_handle_write_data(self, *_args): async def _async_handle_write_data(self, *_args):
"""Handle writing the config.""" """Handle writing the config."""
async with self._write_lock: async with self._write_lock:
self._async_cleanup_delay_listener() self._async_cleanup_delay_listener()
self._async_cleanup_final_write_listener() self._async_cleanup_final_write_listener()

View File

@ -19,7 +19,6 @@ DATA_LOCATION_CACHE = "astral_location_cache"
@bind_hass @bind_hass
def get_astral_location(hass: HomeAssistantType) -> "astral.Location": def get_astral_location(hass: HomeAssistantType) -> "astral.Location":
"""Get an astral location for the current Home Assistant configuration.""" """Get an astral location for the current Home Assistant configuration."""
from astral import Location # pylint: disable=import-outside-toplevel from astral import Location # pylint: disable=import-outside-toplevel
latitude = hass.config.latitude latitude = hass.config.latitude

View File

@ -1292,7 +1292,6 @@ def relative_time(value):
If the input are not a datetime object the input will be returned unmodified. If the input are not a datetime object the input will be returned unmodified.
""" """
if not isinstance(value, datetime): if not isinstance(value, datetime):
return value return value
if not value.tzinfo: if not value.tzinfo:

View File

@ -264,7 +264,6 @@ class CoordinatorEntity(entity.Entity):
Only used by the generic entity update service. Only used by the generic entity update service.
""" """
# Ignore manual update requests if the entity is disabled # Ignore manual update requests if the entity is disabled
if not self.enabled: if not self.enabled:
return return