1616import homeassistant .components .websocket_api .auth as api
1717import homeassistant .helpers .config_validation as cv
1818import voluptuous as vol
19- from homeassistant .components .http import HomeAssistantView
2019from homeassistant .config import DATA_CUSTOMIZE
2120from homeassistant .config_entries import SOURCE_IMPORT , ConfigEntry
2221from homeassistant .const import (CONF_ABOVE , CONF_ACCESS_TOKEN , CONF_BELOW ,
3534from homeassistant .helpers .typing import ConfigType , HomeAssistantType
3635from homeassistant .setup import async_setup_component
3736
37+ from custom_components .remote_homeassistant .views import DiscoveryInfoView
38+
3839from .const import (CONF_EXCLUDE_DOMAINS , CONF_EXCLUDE_ENTITIES ,
3940 CONF_INCLUDE_DOMAINS , CONF_INCLUDE_ENTITIES ,
4041 CONF_LOAD_COMPONENTS , CONF_OPTIONS , CONF_REMOTE_CONNECTION ,
4142 CONF_SERVICE_PREFIX , CONF_SERVICES , CONF_UNSUB_LISTENER ,
42- DOMAIN )
43+ DOMAIN , REMOTE_ID )
4344from .proxy_services import ProxyServices
4445from .rest_api import UnsupportedVersion , async_get_discovery_info
4546
@@ -179,6 +180,10 @@ async def _async_update_config_entry_if_from_yaml(hass, entries_by_id, conf):
179180 hass .config_entries .async_update_entry (entry , data = data , options = options )
180181
181182
183+ async def setup_remote_instance (hass : HomeAssistantType ):
184+ hass .http .register_view (DiscoveryInfoView ())
185+
186+
182187async def async_setup (hass : HomeAssistantType , config : ConfigType ):
183188 """Set up the remote_homeassistant component."""
184189 hass .data .setdefault (DOMAIN , {})
@@ -201,7 +206,7 @@ async def _handle_reload(service):
201206
202207 await asyncio .gather (* update_tasks )
203208
204- hass .http . register_view ( DiscoveryInfoView ( ))
209+ hass .async_create_task ( setup_remote_instance ( hass ))
205210
206211 hass .helpers .service .async_register_admin_service (
207212 DOMAIN ,
@@ -223,29 +228,33 @@ async def _handle_reload(service):
223228async def async_setup_entry (hass : HomeAssistant , entry : ConfigEntry ):
224229 """Set up Remote Home-Assistant from a config entry."""
225230 _async_import_options_from_yaml (hass , entry )
226- remote = RemoteConnection (hass , entry )
227-
228- hass .data [DOMAIN ][entry .entry_id ] = {
229- CONF_REMOTE_CONNECTION : remote ,
230- CONF_UNSUB_LISTENER : entry .add_update_listener (_update_listener ),
231- }
232-
233- async def setup_components_and_platforms ():
234- """Set up platforms and initiate connection."""
235- for domain in entry .options .get (CONF_LOAD_COMPONENTS , []):
236- hass .async_create_task (async_setup_component (hass , domain , {}))
237-
238- await asyncio .gather (
239- * [
240- hass .config_entries .async_forward_entry_setup (entry , platform )
241- for platform in PLATFORMS
242- ]
243- )
244- await remote .async_connect ()
231+ if entry .unique_id == REMOTE_ID :
232+ hass .async_create_task (setup_remote_instance (hass ))
233+ return True
234+ else :
235+ remote = RemoteConnection (hass , entry )
236+
237+ hass .data [DOMAIN ][entry .entry_id ] = {
238+ CONF_REMOTE_CONNECTION : remote ,
239+ CONF_UNSUB_LISTENER : entry .add_update_listener (_update_listener ),
240+ }
241+
242+ async def setup_components_and_platforms ():
243+ """Set up platforms and initiate connection."""
244+ for domain in entry .options .get (CONF_LOAD_COMPONENTS , []):
245+ hass .async_create_task (async_setup_component (hass , domain , {}))
246+
247+ await asyncio .gather (
248+ * [
249+ hass .config_entries .async_forward_entry_setup (entry , platform )
250+ for platform in PLATFORMS
251+ ]
252+ )
253+ await remote .async_connect ()
245254
246- hass .async_create_task (setup_components_and_platforms ())
255+ hass .async_create_task (setup_components_and_platforms ())
247256
248- return True
257+ return True
249258
250259
251260async def async_unload_entry (hass : HomeAssistant , entry : ConfigEntry ):
@@ -425,7 +434,7 @@ def _async_instance_id_match(info):
425434 name = info .get ("location_name" ),
426435 manufacturer = "Home Assistant" ,
427436 model = info .get ("installation_type" ),
428- sw_version = info .get ("version " ),
437+ sw_version = info .get ("ha_version " ),
429438 )
430439
431440 asyncio .ensure_future (self ._recv ())
@@ -729,20 +738,3 @@ def got_states(message):
729738 await self .call (got_states , "get_states" )
730739
731740 await self .proxy_services .load ()
732-
733-
734- class DiscoveryInfoView (HomeAssistantView ):
735- """Get all logged errors and warnings."""
736-
737- url = "/api/remote_homeassistant/discovery"
738- name = "api:remote_homeassistant:discovery"
739-
740- async def get (self , request ):
741- """Get discovery information."""
742- hass = request .app ["hass" ]
743- return self .json (
744- {
745- "uuid" : await hass .helpers .instance_id .async_get (),
746- "location_name" : hass .config .location_name ,
747- }
748- )
0 commit comments