1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-13 17:44:45 +01:00
Files
core/homeassistant/components/subaru/remote_service.py
T

36 lines
1.1 KiB
Python

"""Remote vehicle services for Subaru integration."""
import logging
from subarulink.exceptions import SubaruException
from homeassistant.const import SERVICE_UNLOCK
from homeassistant.exceptions import HomeAssistantError
from .const import SERVICE_REMOTE_START, VEHICLE_NAME, VEHICLE_VIN
_LOGGER = logging.getLogger(__name__)
async def async_call_remote_service(controller, cmd, vehicle_info, arg=None):
"""Execute subarulink remote command."""
car_name = vehicle_info[VEHICLE_NAME]
vin = vehicle_info[VEHICLE_VIN]
_LOGGER.debug("Sending %s command command to %s", cmd, car_name)
success = False
err_msg = ""
try:
if cmd in (SERVICE_UNLOCK, SERVICE_REMOTE_START):
success = await getattr(controller, cmd)(vin, arg)
else:
success = await getattr(controller, cmd)(vin)
except SubaruException as err:
err_msg = err.message
if success:
_LOGGER.debug("%s command successfully completed for %s", cmd, car_name)
return
raise HomeAssistantError(f"Service {cmd} failed for {car_name}: {err_msg}")