Raise errors on action call problems

This commit is contained in:
Ville Skyttä 2025-05-04 14:18:35 +03:00
parent 8046684179
commit a159f357ae

View File

@ -40,7 +40,11 @@ from homeassistant.const import (
Platform, Platform,
) )
from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import (
ConfigEntryAuthFailed,
ConfigEntryNotReady,
ServiceValidationError,
)
from homeassistant.helpers import ( from homeassistant.helpers import (
config_validation as cv, config_validation as cv,
device_registry as dr, device_registry as dr,
@ -512,20 +516,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
(router for router in routers.values() if router.url == url), None (router for router in routers.values() if router.url == url), None
) )
elif not routers: elif not routers:
_LOGGER.error("%s: no routers configured", service.service) raise ServiceValidationError("No routers configured")
return
elif len(routers) == 1: elif len(routers) == 1:
router = next(iter(routers.values())) router = next(iter(routers.values()))
else: else:
_LOGGER.error( raise ServiceValidationError(
"%s: more than one router configured, must specify one of URLs %s", f"More than one router configured, must specify one of URLs {sorted(router.url for router in routers.values())}"
service.service,
sorted(router.url for router in routers.values()),
) )
return
if not router: if not router:
_LOGGER.error("%s: router %s unavailable", service.service, url) raise ServiceValidationError(f"Router {url} not available")
return
if service.service == SERVICE_RESUME_INTEGRATION: if service.service == SERVICE_RESUME_INTEGRATION:
# Login will be handled automatically on demand # Login will be handled automatically on demand
@ -536,7 +535,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
router.suspended = True router.suspended = True
_LOGGER.debug("%s: %s", service.service, "done") _LOGGER.debug("%s: %s", service.service, "done")
else: else:
_LOGGER.error("%s: unsupported service", service.service) raise ServiceValidationError(f"Unsupported service {service.service}")
for service in ADMIN_SERVICES: for service in ADMIN_SERVICES:
async_register_admin_service( async_register_admin_service(