From a9875b597bd5f8c983c01625277d9a6c67735c3a Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 25 Aug 2026 10:02:00 +0200 Subject: [PATCH] Use get_device_and_config_entry_for_domain in switchbot_cloud (#180112) --- homeassistant/components/switchbot_cloud/service.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/switchbot_cloud/service.py b/homeassistant/components/switchbot_cloud/service.py index d1121154115d..dbc863729248 100644 --- a/homeassistant/components/switchbot_cloud/service.py +++ b/homeassistant/components/switchbot_cloud/service.py @@ -29,10 +29,11 @@ async def handle_upload_image(call: ServiceCall) -> None: hass = call.hass image_url = call.data["image_url"] device_ids = call.data.get("device_id", []) - dev_reg = dr.async_get(hass) for ha_device_id in device_ids: - device = dev_reg.async_get(ha_device_id) + device, config_entry = dr.async_get_device_and_config_entry_for_domain( + hass, ha_device_id, domain=DOMAIN + ) if device is None: raise ServiceValidationError(f"Device {ha_device_id} not found") @@ -40,15 +41,11 @@ async def handle_upload_image(call: ServiceCall) -> None: (iid[1] for iid in device.identifiers if iid[0] == DOMAIN), None ) if device_mac: - for config_entry_id in device.config_entries: - entry = hass.config_entries.async_get_entry(config_entry_id) - if entry is not None and entry.domain == DOMAIN: - break - else: + if config_entry is None: raise ServiceValidationError( f"Device {ha_device_id} is not a SwitchBot Cloud device" ) - await entry.runtime_data.api.send_command( + await config_entry.runtime_data.api.send_command( device_id=device_mac, command=ArtFrameCommands.UPLOAD.value, command_type="command",