Skip to content

Commit

Permalink
Match on word 'all'
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Dec 6, 2018
1 parent c084656 commit b4984c0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# Can be used to specify a catch all when registering state or event listeners.
MATCH_ALL = '*'

# Entity target all constant
ENTITY_MATCH_ALL = 'all'

# If no name is specified
DEVICE_DEFAULT_NAME = 'Unnamed Device'

Expand Down
7 changes: 5 additions & 2 deletions homeassistant/helpers/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CONF_ALIAS, CONF_ENTITY_ID, CONF_VALUE_TEMPLATE, WEEKDAYS,
CONF_CONDITION, CONF_BELOW, CONF_ABOVE, CONF_TIMEOUT, SUN_EVENT_SUNSET,
SUN_EVENT_SUNRISE, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC,
MATCH_ALL)
ENTITY_MATCH_ALL)
from homeassistant.core import valid_entity_id, split_entity_id
from homeassistant.exceptions import TemplateError
import homeassistant.util.dt as dt_util
Expand Down Expand Up @@ -162,7 +162,10 @@ def entity_ids(value: Union[str, Sequence]) -> Sequence[str]:
return [entity_id(ent_id) for ent_id in value]


comp_entity_ids = vol.Any(MATCH_ALL, entity_ids)
comp_entity_ids = vol.Any(
vol.All(vol.Lower, ENTITY_MATCH_ALL),
entity_ids
)


def entity_domain(domain: str):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/helpers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import voluptuous as vol

from homeassistant.auth.permissions.const import POLICY_CONTROL
from homeassistant.const import ATTR_ENTITY_ID, MATCH_ALL
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL
import homeassistant.core as ha
from homeassistant.exceptions import TemplateError, Unauthorized, UnknownUser
from homeassistant.helpers import template
Expand Down Expand Up @@ -198,7 +198,7 @@ async def entity_service_call(hass, platforms, func, call):

# Are we trying to target all entities
if ATTR_ENTITY_ID in call.data:
target_all_entities = call.data[ATTR_ENTITY_ID] == MATCH_ALL
target_all_entities = call.data[ATTR_ENTITY_ID] == ENTITY_MATCH_ALL
else:
_LOGGER.warning('Not passing an entity ID to a service to target all '
'entities is deprecated. Use instead: entity_id: "*"')
Expand Down
13 changes: 13 additions & 0 deletions tests/helpers/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,16 @@ def test_is_regex():

valid_re = ".*"
schema(valid_re)


def test_comp_entity_ids():
"""Test config validation for component entity IDs."""
schema = vol.Schema(cv.comp_entity_ids)

for valid in ('ALL', 'all', 'AlL', 'light.kitchen', ['light.kitchen'],
['light.kitchen', 'light.ceiling'], []):
schema(valid)

for invalid in (['light.kitchen', 'not-entity-id'], '*', ''):
with pytest.raises(vol.Invalid):
schema(invalid)
2 changes: 1 addition & 1 deletion tests/helpers/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ async def test_call_with_match_all(hass, mock_service_platform_call,
await service.entity_service_call(hass, [
Mock(entities=mock_entities)
], Mock(), ha.ServiceCall('test_domain', 'test_service', {
'entity_id': '*'
'entity_id': 'all'
}))

assert len(mock_service_platform_call.mock_calls) == 1
Expand Down

0 comments on commit b4984c0

Please sign in to comment.