33from datetime import timedelta
44import logging
55
6- from httpx import HTTPError , InvalidURL
6+ from httpx import HTTPError , InvalidURL , TimeoutException
77from ical .calendar import Calendar
88
99from homeassistant .config_entries import ConfigEntry
1212from homeassistant .helpers .httpx_client import get_async_client
1313from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
1414
15+ from .client import get_calendar
1516from .const import DOMAIN
1617from .ics import InvalidIcsException , parse_calendar
1718
@@ -36,7 +37,7 @@ def __init__(
3637 super ().__init__ (
3738 hass ,
3839 _LOGGER ,
39- name = DOMAIN ,
40+ name = f" { DOMAIN } _ { config_entry . title } " ,
4041 update_interval = SCAN_INTERVAL ,
4142 always_update = True ,
4243 )
@@ -46,13 +47,19 @@ def __init__(
4647 async def _async_update_data (self ) -> Calendar :
4748 """Update data from the url."""
4849 try :
49- res = await self ._client . get ( self ._url , follow_redirects = True )
50+ res = await get_calendar ( self ._client , self ._url )
5051 res .raise_for_status ()
52+ except TimeoutException as err :
53+ _LOGGER .debug ("%s: %s" , self ._url , str (err ) or type (err ).__name__ )
54+ raise UpdateFailed (
55+ translation_domain = DOMAIN ,
56+ translation_key = "timeout" ,
57+ ) from err
5158 except (HTTPError , InvalidURL ) as err :
59+ _LOGGER .debug ("%s: %s" , self ._url , str (err ) or type (err ).__name__ )
5260 raise UpdateFailed (
5361 translation_domain = DOMAIN ,
5462 translation_key = "unable_to_fetch" ,
55- translation_placeholders = {"err" : str (err )},
5663 ) from err
5764 try :
5865 self .ics = res .text
0 commit comments