1111
1212from homeassistant import config_entries
1313from homeassistant .config_entries import ConfigFlowResult
14- from homeassistant .core import callback
14+ from homeassistant .core import HomeAssistant , callback
1515from homeassistant .helpers import config_validation as cv
16+ from homeassistant .helpers .aiohttp_client import async_get_clientsession
1617
1718from .const import (
1819 CONF_GPS ,
@@ -49,16 +50,22 @@ async def validate_url(url: str) -> bool:
4950 return bool (re .match (pattern , url ))
5051
5152
52- async def validate_station (station : int , solver : str | None = None ) -> bool :
53+ async def validate_station (
54+ hass : HomeAssistant , station : int , solver : str | None = None
55+ ) -> bool :
5356 """Validate statation ID."""
54- check = await py_gasbuddy .GasBuddy (solver_url = solver , station_id = station ).price_lookup ()
57+ check = await py_gasbuddy .GasBuddy (
58+ solver_url = solver ,
59+ station_id = station ,
60+ session = async_get_clientsession (hass ),
61+ ).price_lookup ()
5562
5663 if "errors" in check :
5764 return False
5865 return True
5966
6067
61- async def _get_station_list (hass , user_input ) -> dict [str , Any ]:
68+ async def _get_station_list (hass : HomeAssistant , user_input ) -> dict [str , Any ]:
6269 """Return list of utilities by lat/lon."""
6370 lat = None
6471 lon = None
@@ -77,9 +84,10 @@ async def _get_station_list(hass, user_input) -> dict[str, Any]:
7784 solver = user_input [CONF_SOLVER ]
7885 _LOGGER .debug ("Using solver URL: %s" , solver )
7986
80- stations = await py_gasbuddy .GasBuddy (solver_url = solver ).location_search (
81- lat = lat , lon = lon , zipcode = postal
82- )
87+ stations = await py_gasbuddy .GasBuddy (
88+ solver_url = solver ,
89+ session = async_get_clientsession (hass ),
90+ ).location_search (lat = lat , lon = lon , zipcode = postal )
8391 stations_list = {}
8492 _LOGGER .debug ("search reply: %s" , stations )
8593
@@ -267,7 +275,7 @@ async def async_step_manual(self, user_input=None):
267275 self ._errors [CONF_SOLVER ] = "invalid_url"
268276 return await self ._show_config_manual (user_input )
269277
270- validate = await validate_station (user_input [CONF_STATION_ID ], user_input [CONF_SOLVER ])
278+ validate = await validate_station (self . hass , user_input [CONF_STATION_ID ], user_input [CONF_SOLVER ])
271279 if not validate :
272280 self ._errors [CONF_STATION_ID ] = "station_id"
273281 else :
@@ -427,7 +435,7 @@ async def async_step_reconfigure(self, user_input: dict[str, Any] | None = None)
427435 else :
428436 user_input [CONF_SOLVER ] = None
429437
430- validate = await validate_station (user_input [CONF_STATION_ID ], user_input [CONF_SOLVER ])
438+ validate = await validate_station (self . hass , user_input [CONF_STATION_ID ], user_input [CONF_SOLVER ])
431439 if not validate :
432440 self ._errors [CONF_STATION_ID ] = "station_id"
433441
0 commit comments