Make ATTR_ENTITY_ID required in local_file service call (#63017)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/63224/head
epenet 2022-01-02 17:20:46 +01:00 committed by GitHub
parent 71a5b89691
commit d8dabd305c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
from homeassistant.const import ATTR_ENTITY_ID, CONF_FILE_PATH, CONF_NAME
from homeassistant.core import ServiceCall
from homeassistant.helpers import config_validation as cv
from .const import DATA_LOCAL_FILE, DEFAULT_NAME, DOMAIN, SERVICE_UPDATE_FILE_PATH
@ -24,7 +25,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
CAMERA_SERVICE_UPDATE_FILE_PATH = vol.Schema(
{
vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(ATTR_ENTITY_ID): cv.comp_entity_ids,
vol.Required(CONF_FILE_PATH): cv.string,
}
)
@ -39,16 +40,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
camera = LocalFile(config[CONF_NAME], file_path)
hass.data[DATA_LOCAL_FILE].append(camera)
def update_file_path_service(call):
def update_file_path_service(call: ServiceCall) -> None:
"""Update the file path."""
file_path = call.data.get(CONF_FILE_PATH)
entity_ids = call.data.get(ATTR_ENTITY_ID)
file_path = call.data[CONF_FILE_PATH]
entity_ids = call.data[ATTR_ENTITY_ID]
cameras = hass.data[DATA_LOCAL_FILE]
for camera in cameras:
if camera.entity_id in entity_ids:
camera.update_file_path(file_path)
return True
hass.services.register(
DOMAIN,