@@ -102,23 +102,23 @@ def token(self) -> str:
102102 """Get token for device."""
103103 return self ._token
104104
105+ def _get_hass_url (self ) -> str :
106+ """Get the Home Assistant URL for this device."""
107+ if custom_url := self .custom_url :
108+ return custom_url
109+ return get_url (self ._hass , prefer_external = False )
110+
105111 async def async_register_events (self ) -> None :
106112 """Register events on device."""
107113 if not self .door_station_events :
108114 # The config entry might not have any events configured yet
109115 return
110- # Override url if another is specified in the configuration
111- if custom_url := self .custom_url :
112- hass_url = custom_url
113- else :
114- # Get the URL of this server
115- hass_url = get_url (self ._hass , prefer_external = False )
116- http_fav = await self ._async_register_events (hass_url )
117- event_config = await self ._async_get_event_config (http_fav , hass_url )
116+ http_fav = await self ._async_register_events ()
117+ event_config = await self ._async_get_event_config (http_fav )
118118 _LOGGER .debug ("%s: Event config: %s" , self .name , event_config )
119119 if event_config .unconfigured_favorites :
120120 await self ._configure_unconfigured_favorites (event_config )
121- event_config = await self ._async_get_event_config (http_fav , hass_url )
121+ event_config = await self ._async_get_event_config (http_fav )
122122 self .event_descriptions = event_config .events
123123
124124 async def _configure_unconfigured_favorites (
@@ -150,8 +150,9 @@ async def _configure_unconfigured_favorites(
150150 code ,
151151 )
152152
153- async def _async_register_events (self , hass_url : str ) -> dict [str , Any ]:
153+ async def _async_register_events (self ) -> dict [str , Any ]:
154154 """Register events on device."""
155+ hass_url = self ._get_hass_url ()
155156 http_fav = await self ._async_get_http_favorites ()
156157 if any (
157158 # Note that a list comp is used here to ensure all
@@ -167,7 +168,7 @@ async def _async_register_events(self, hass_url: str) -> dict[str, Any]:
167168 return http_fav
168169
169170 async def _async_get_event_config (
170- self , http_fav : dict [str , dict [str , Any ]], hass_url : str
171+ self , http_fav : dict [str , dict [str , Any ]]
171172 ) -> DoorbirdEventConfig :
172173 """Get events and unconfigured favorites from http favorites."""
173174 device = self .device
@@ -190,6 +191,7 @@ async def _async_get_event_config(
190191 self ._get_event_name (event ): event_type
191192 for event , event_type in DEFAULT_EVENT_TYPES
192193 }
194+ hass_url = self ._get_hass_url ()
193195 for identifier , data in http_fav .items ():
194196 title : str | None = data .get ("title" )
195197 if not title or not title .startswith ("Home Assistant" ):
0 commit comments