Home Assistant Unofficial Reference 2024.12.1
remote_service.py
Go to the documentation of this file.
1 """Remote vehicle services for Subaru integration."""
2 
3 import logging
4 
5 from subarulink.exceptions import SubaruException
6 
7 from homeassistant.exceptions import HomeAssistantError
8 
9 from .const import SERVICE_UNLOCK, VEHICLE_NAME, VEHICLE_VIN
10 
11 _LOGGER = logging.getLogger(__name__)
12 
13 
14 async def async_call_remote_service(controller, cmd, vehicle_info, arg=None):
15  """Execute subarulink remote command."""
16  car_name = vehicle_info[VEHICLE_NAME]
17  vin = vehicle_info[VEHICLE_VIN]
18 
19  _LOGGER.debug("Sending %s command command to %s", cmd, car_name)
20  success = False
21  err_msg = ""
22  try:
23  if cmd == SERVICE_UNLOCK:
24  success = await getattr(controller, cmd)(vin, arg)
25  else:
26  success = await getattr(controller, cmd)(vin)
27  except SubaruException as err:
28  err_msg = err.message
29 
30  if success:
31  _LOGGER.debug("%s command successfully completed for %s", cmd, car_name)
32  return
33 
34  raise HomeAssistantError(f"Service {cmd} failed for {car_name}: {err_msg}")
def async_call_remote_service(controller, cmd, vehicle_info, arg=None)