mirror of
https://github.com/home-assistant/core.git
synced 2025-07-05 20:37:16 +00:00
Simplify swiss public transport service actions (#146611)
This commit is contained in:
parent
171f7c5f81
commit
b0cf974b34
@ -35,7 +35,7 @@ from .coordinator import (
|
|||||||
SwissPublicTransportDataUpdateCoordinator,
|
SwissPublicTransportDataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
from .helper import offset_opendata, unique_id_from_config
|
from .helper import offset_opendata, unique_id_from_config
|
||||||
from .services import setup_services
|
from .services import async_setup_services
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
|||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Swiss public transport component."""
|
"""Set up the Swiss public transport component."""
|
||||||
setup_services(hass)
|
async_setup_services(hass)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from homeassistant.core import (
|
|||||||
ServiceCall,
|
ServiceCall,
|
||||||
ServiceResponse,
|
ServiceResponse,
|
||||||
SupportsResponse,
|
SupportsResponse,
|
||||||
|
callback,
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers.selector import (
|
from homeassistant.helpers.selector import (
|
||||||
@ -39,7 +40,7 @@ SERVICE_FETCH_CONNECTIONS_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def async_get_entry(
|
def _async_get_entry(
|
||||||
hass: HomeAssistant, config_entry_id: str
|
hass: HomeAssistant, config_entry_id: str
|
||||||
) -> SwissPublicTransportConfigEntry:
|
) -> SwissPublicTransportConfigEntry:
|
||||||
"""Get the Swiss public transport config entry."""
|
"""Get the Swiss public transport config entry."""
|
||||||
@ -58,14 +59,11 @@ def async_get_entry(
|
|||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
def setup_services(hass: HomeAssistant) -> None:
|
async def _async_fetch_connections(
|
||||||
"""Set up the services for the Swiss public transport integration."""
|
|
||||||
|
|
||||||
async def async_fetch_connections(
|
|
||||||
call: ServiceCall,
|
call: ServiceCall,
|
||||||
) -> ServiceResponse:
|
) -> ServiceResponse:
|
||||||
"""Fetch a set of connections."""
|
"""Fetch a set of connections."""
|
||||||
config_entry = async_get_entry(hass, call.data[ATTR_CONFIG_ENTRY_ID])
|
config_entry = _async_get_entry(call.hass, call.data[ATTR_CONFIG_ENTRY_ID])
|
||||||
|
|
||||||
limit = call.data.get(ATTR_LIMIT) or CONNECTIONS_COUNT
|
limit = call.data.get(ATTR_LIMIT) or CONNECTIONS_COUNT
|
||||||
try:
|
try:
|
||||||
@ -82,10 +80,15 @@ def setup_services(hass: HomeAssistant) -> None:
|
|||||||
) from e
|
) from e
|
||||||
return {"connections": connections}
|
return {"connections": connections}
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
|
"""Set up the services for the Swiss public transport integration."""
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_FETCH_CONNECTIONS,
|
SERVICE_FETCH_CONNECTIONS,
|
||||||
async_fetch_connections,
|
_async_fetch_connections,
|
||||||
schema=SERVICE_FETCH_CONNECTIONS_SCHEMA,
|
schema=SERVICE_FETCH_CONNECTIONS_SCHEMA,
|
||||||
supports_response=SupportsResponse.ONLY,
|
supports_response=SupportsResponse.ONLY,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user