Align valid_entity_id with new slugify (#20231)

* slug

* ensure a dot

* fix

* schema_with_slug_keys

* lint

* test
This commit is contained in:
Johann Kellerman authored and Paulus Schoutsen committed 2019-01-21 09:45:11 -08:00
1 parent 6ca0da5c52
commit c36c708068
5 files changed
+32 -17

No files matched your search

+7 -7
View File
@@ -12,7 +12,6 @@ import functools
import logging
import os
import pathlib
import re
import sys
import threading
from time import monotonic
@@ -43,7 +42,7 @@ from homeassistant.util.async_ import (
fire_coroutine_threadsafe)
from homeassistant import util
import homeassistant.util.dt as dt_util
from homeassistant.util import location
from homeassistant.util import location, slugify
from homeassistant.util.unit_system import UnitSystem, METRIC_SYSTEM # NOQA
# Typing imports that create a circular dependency
@@ -62,9 +61,6 @@ DOMAIN = 'homeassistant'
# How long we wait for the result of a service call
SERVICE_CALL_LIMIT = 10 # seconds
# Pattern for validating entity IDs (format: <domain>.<entity>)
ENTITY_ID_PATTERN = re.compile(r"^(\w+)\.(\w+)$")
# How long to wait till things that run on startup have to finish.
TIMEOUT_EVENT_START = 15
@@ -77,8 +73,12 @@ def split_entity_id(entity_id: str) -> List[str]:
def valid_entity_id(entity_id: str) -> bool:
"""Test if an entity ID is a valid format."""
return ENTITY_ID_PATTERN.match(entity_id) is not None
"""Test if an entity ID is a valid format.
Format: <domain>.<entity> where both are slugs.
"""
return ('.' in entity_id and
slugify(entity_id) == entity_id.replace('.', '_', 1))
def valid_state(state: str) -> bool: