From 16ae7fc277c1aadee52f8591746c8a4509d26eda Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 8 Dec 2023 10:09:53 +0100 Subject: [PATCH] Fix accepting list of devices in enable/disable service (#472) --- .../homeassistant/services/disable_device.py | 11 ++++++----- .../homeassistant/services/enable_device.py | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/custom_components/spook/ectoplasms/homeassistant/services/disable_device.py b/custom_components/spook/ectoplasms/homeassistant/services/disable_device.py index 6ef84422..f6b9cb95 100644 --- a/custom_components/spook/ectoplasms/homeassistant/services/disable_device.py +++ b/custom_components/spook/ectoplasms/homeassistant/services/disable_device.py @@ -19,12 +19,13 @@ class SpookService(AbstractSpookAdminService): domain = DOMAIN service = "disable_device" - schema = {vol.Required("device_id"): cv.string} + schema = {vol.Required("device_id"): vol.All(cv.ensure_list, [cv.string])} async def async_handle_service(self, call: ServiceCall) -> None: """Handle the service call.""" device_registry = dr.async_get(self.hass) - device_registry.async_update_device( - device_id=call.data["device_id"], - disabled_by=dr.DeviceEntryDisabler.USER, - ) + for device_id in call.data["device_id"]: + device_registry.async_update_device( + device_id=device_id, + disabled_by=dr.DeviceEntryDisabler.USER, + ) diff --git a/custom_components/spook/ectoplasms/homeassistant/services/enable_device.py b/custom_components/spook/ectoplasms/homeassistant/services/enable_device.py index e52f9fe0..a60f7992 100644 --- a/custom_components/spook/ectoplasms/homeassistant/services/enable_device.py +++ b/custom_components/spook/ectoplasms/homeassistant/services/enable_device.py @@ -19,12 +19,13 @@ class SpookService(AbstractSpookAdminService): domain = DOMAIN service = "enable_device" - schema = {vol.Required("device_id"): cv.string} + schema = {vol.Required("device_id"): vol.All(cv.ensure_list, [cv.string])} async def async_handle_service(self, call: ServiceCall) -> None: """Handle the service call.""" device_registry = dr.async_get(self.hass) - device_registry.async_update_device( - device_id=call.data["device_id"], - disabled_by=None, - ) + for device_id in call.data["device_id"]: + device_registry.async_update_device( + device_id=device_id, + disabled_by=None, + )