Skip to content

Commit

Permalink
Adjust services
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Apr 30, 2024
1 parent 7f34290 commit bf34bc6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions homeassistant/components/renault/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

import voluptuous as vol

from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import config_validation as cv, device_registry as dr

from .const import DOMAIN
from .renault_hub import RenaultHub
from .renault_vehicle import RenaultVehicleProxy

if TYPE_CHECKING:
from . import RenaultConfigEntry

LOGGER = logging.getLogger(__name__)

ATTR_SCHEDULES = "schedules"
Expand Down Expand Up @@ -116,9 +119,13 @@ def get_vehicle_proxy(service_call_data: Mapping) -> RenaultVehicleProxy:
if device_entry is None:
raise ValueError(f"Unable to find device with id: {device_id}")

proxy: RenaultHub
for proxy in hass.data[DOMAIN].values():
for vin, vehicle in proxy.vehicles.items():
loaded_entries: list[RenaultConfigEntry] = [
entry
for entry in hass.config_entries.async_entries(DOMAIN)
if entry.state == ConfigEntryState.LOADED
]
for entry in loaded_entries:
for vin, vehicle in entry.runtime_data.vehicles.items():
if (DOMAIN, vin) in device_entry.identifiers:
return vehicle
raise ValueError(f"Unable to find vehicle with VIN: {device_entry.identifiers}")
Expand Down

0 comments on commit bf34bc6

Please sign in to comment.