Log warning when entities referenced in service call not found (#31427)

* Raise entities not found error

* Make it a warning, not an error

* Add support for MATCH_ENTITY_NONE

* Fix lint

* Fix tests
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-02-04 14:42:07 -08:00
1 parent 201ea2557e
commit f41623ca64
16 files changed
+339 -89

No files matched your search

@@ -23,6 +23,7 @@ from homeassistant.const import (
CONF_SENSORS,
CONF_USERNAME,
ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE,
HTTP_BASIC_AUTHENTICATION,
)
from homeassistant.exceptions import Unauthorized, UnknownUser
@@ -236,6 +237,9 @@ def setup(hass, config):
if have_permission(user, entity_id)
]
if call.data.get(ATTR_ENTITY_ID) == ENTITY_MATCH_NONE:
return []
call_ids = await async_extract_entity_ids(hass, call)
entity_ids = []
for entity_id in hass.data[DATA_AMCREST][CAMERAS]:
@@ -30,6 +30,7 @@ from homeassistant.const import (
CONF_TIMEOUT,
CONF_ZONE,
ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE,
STATE_OFF,
STATE_ON,
STATE_PAUSED,
@@ -201,6 +202,10 @@ class DenonDevice(MediaPlayerDevice):
def signal_handler(self, data):
"""Handle domain-specific signal by calling appropriate method."""
entity_ids = data[ATTR_ENTITY_ID]
if entity_ids == ENTITY_MATCH_NONE:
return
if entity_ids == ENTITY_MATCH_ALL or self.entity_id in entity_ids:
params = {
key: value
+4 -1
View File
@@ -11,6 +11,7 @@ from homeassistant.const import (
CONF_PLATFORM,
CONF_PORT,
ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE,
)
import homeassistant.helpers.config_validation as cv
@@ -136,7 +137,9 @@ DEL_ALL_LINK_SCHEMA = vol.Schema(
LOAD_ALDB_SCHEMA = vol.Schema(
{
vol.Required(CONF_ENTITY_ID): vol.Any(cv.entity_id, ENTITY_MATCH_ALL),
vol.Required(CONF_ENTITY_ID): vol.Any(
cv.entity_id, ENTITY_MATCH_ALL, ENTITY_MATCH_NONE
),
vol.Optional(SRV_LOAD_DB_RELOAD, default=False): cv.boolean,
}
)
+4
View File
@@ -39,6 +39,7 @@ from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_MODE,
ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import callback
@@ -374,6 +375,9 @@ class LIFXManager:
async def async_service_to_entities(self, service):
"""Return the known entities that a service call mentions."""
if service.data.get(ATTR_ENTITY_ID) == ENTITY_MATCH_NONE:
return []
if service.data.get(ATTR_ENTITY_ID) == ENTITY_MATCH_ALL:
return self.entities.values()
+3 -3
View File
@@ -22,7 +22,7 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_MUSIC,
SERVICE_PLAY_MEDIA,
)
from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM, ENTITY_MATCH_ALL
from homeassistant.const import ATTR_ENTITY_ID, CONF_PLATFORM
from homeassistant.core import callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_per_platform, discovery
@@ -90,7 +90,7 @@ SCHEMA_SERVICE_SAY = vol.Schema(
{
vol.Required(ATTR_MESSAGE): cv.string,
vol.Optional(ATTR_CACHE): cv.boolean,
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Optional(ATTR_LANGUAGE): cv.string,
vol.Optional(ATTR_OPTIONS): dict,
}
@@ -148,7 +148,7 @@ async def async_setup(hass, config):
async def async_say_handle(service):
"""Service handle for say."""
entity_ids = service.data.get(ATTR_ENTITY_ID, ENTITY_MATCH_ALL)
entity_ids = service.data[ATTR_ENTITY_ID]
message = service.data.get(ATTR_MESSAGE)
cache = service.data.get(ATTR_CACHE)
language = service.data.get(ATTR_LANGUAGE)
@@ -29,6 +29,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_NAME,
ENTITY_MATCH_ALL,
ENTITY_MATCH_NONE,
STATE_OFF,
STATE_ON,
)
@@ -137,6 +138,9 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
async def async_signal_handler(self, data):
"""Handle domain-specific signal by calling appropriate method."""
entity_ids = data[ATTR_ENTITY_ID]
if entity_ids == ENTITY_MATCH_NONE:
return
if entity_ids == ENTITY_MATCH_ALL or self.entity_id in entity_ids:
params = {
key: value