Skip to content

Commit e31c186

Browse files
authored
Add option to load components present on remote (#83)
1 parent 5d70cd1 commit e31c186

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ remote_homeassistant:
129129
- service_registered
130130
- zwave.network_ready
131131
- zwave.node_event
132+
load_components:
133+
- zwave
132134
```
133135
134136
```
@@ -206,19 +208,27 @@ subscribe_events:
206208
default:
207209
- state_changed
208210
- service_registered
211+
load_components:
212+
description: Load components of specified domains only present on the remote instance, e.g. to register services that would otherwise not be available.
213+
required: false
214+
type: list
209215
```
210216
211217
## Special notes
212218
213-
If you have remote domains (e.g. `switch`), that are not loaded on the master instance you need to add a dummy entry on the master, otherwise you'll get a `Call service failed` error.
219+
If you have remote domains (e.g. `switch`), that are not loaded on the master instance you need to list them under `load_components`, otherwise you'll get a `Call service failed` error.
214220

215221
E.g. on the master:
216222

217223
```
218-
switch:
224+
remote_homeassistant:
225+
instances:
226+
- host: 10.0.0.2
227+
load_components:
228+
- zwave
219229
```
220230

221-
to enable all `switch` services.
231+
to enable all `zwave` services. This can also be configured via options under Configuration->Integrations.
222232

223233
---
224234

custom_components/remote_homeassistant/__init__.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from homeassistant.helpers.reload import async_integration_yaml_config
4747
import homeassistant.helpers.config_validation as cv
4848
from homeassistant.helpers.dispatcher import async_dispatcher_send
49+
from homeassistant.setup import async_setup_component
4950

5051
from .const import (
5152
CONF_REMOTE_CONNECTION,
@@ -56,6 +57,7 @@
5657
CONF_EXCLUDE_ENTITIES,
5758
CONF_OPTIONS,
5859
CONF_REMOTE_INFO,
60+
CONF_LOAD_COMPONENTS,
5961
DOMAIN,
6062
)
6163
from .rest_api import UnsupportedVersion, async_get_discovery_info
@@ -121,6 +123,7 @@
121123
CONF_SUBSCRIBE_EVENTS, default=DEFAULT_SUBSCRIBED_EVENTS
122124
): cv.ensure_list,
123125
vol.Optional(CONF_ENTITY_PREFIX, default=DEFAULT_ENTITY_PREFIX): cv.string,
126+
vol.Optional(CONF_LOAD_COMPONENTS): cv.ensure_list,
124127
}
125128
)
126129

@@ -160,14 +163,14 @@ def async_yaml_to_config_entry(instance_conf):
160163
if CONF_DOMAINS in exclude:
161164
options[CONF_EXCLUDE_DOMAINS] = exclude[CONF_DOMAINS]
162165

163-
if CONF_FILTER in conf:
164-
options[CONF_FILTER] = conf.pop(CONF_FILTER)
165-
166-
if CONF_SUBSCRIBE_EVENTS in conf:
167-
options[CONF_SUBSCRIBE_EVENTS] = conf.pop(CONF_SUBSCRIBE_EVENTS)
168-
169-
if CONF_ENTITY_PREFIX in conf:
170-
options[CONF_ENTITY_PREFIX] = conf.pop(CONF_ENTITY_PREFIX)
166+
for option in [
167+
CONF_FILTER,
168+
CONF_SUBSCRIBE_EVENTS,
169+
CONF_ENTITY_PREFIX,
170+
CONF_LOAD_COMPONENTS,
171+
]:
172+
if option in conf:
173+
options[option] = conf.pop(option)
171174

172175
return conf, options
173176

@@ -240,15 +243,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
240243
CONF_UNSUB_LISTENER: entry.add_update_listener(_update_listener),
241244
}
242245

243-
async def setup_platforms():
246+
async def setup_components_and_platforms():
244247
"""Set up platforms and initiate connection."""
248+
for domain in entry.options.get(CONF_LOAD_COMPONENTS, []):
249+
hass.async_create_task(async_setup_component(hass, domain, {}))
245250
for component in PLATFORMS:
246251
hass.async_create_task(
247252
hass.config_entries.async_forward_entry_setup(entry, component)
248253
)
249254
await remote.async_connect()
250255

251-
hass.async_create_task(setup_platforms())
256+
hass.async_create_task(setup_components_and_platforms())
252257

253258
return True
254259

custom_components/remote_homeassistant/config_flow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from .const import (
3636
CONF_REMOTE_CONNECTION,
3737
CONF_SECURE,
38+
CONF_LOAD_COMPONENTS,
3839
CONF_FILTER,
3940
CONF_SUBSCRIBE_EVENTS,
4041
CONF_ENTITY_PREFIX,
@@ -196,6 +197,8 @@ async def async_step_init(self, user_input=None):
196197
self.options = user_input.copy()
197198
return await self.async_step_domain_entity_filters()
198199

200+
domains, _ = self._domains_and_entities()
201+
domains = set(domains + self.config_entry.options.get(CONF_LOAD_COMPONENTS, []))
199202
return self.async_show_form(
200203
step_id="init",
201204
data_schema=vol.Schema(
@@ -207,7 +210,11 @@ async def async_step_init(self, user_input=None):
207210
CONF_ENTITY_PREFIX
208211
)
209212
},
210-
): str
213+
): str,
214+
vol.Optional(
215+
CONF_LOAD_COMPONENTS,
216+
default=self._default(CONF_LOAD_COMPONENTS),
217+
): cv.multi_select(sorted(domains)),
211218
}
212219
),
213220
)

custom_components/remote_homeassistant/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
CONF_UNSUB_LISTENER = "unsub_listener"
55
CONF_OPTIONS = "options"
66
CONF_REMOTE_INFO = "remote_info"
7+
CONF_LOAD_COMPONENTS = "load_components"
78

89
CONF_FILTER = "filter"
910
CONF_SECURE = "secure"

custom_components/remote_homeassistant/translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"init": {
4040
"title": "Basic Options (step 1/4)",
4141
"data": {
42-
"entity_prefix": "Entity prefix (optional)"
42+
"entity_prefix": "Entity prefix (optional)",
43+
"load_components": "Load component (if not loaded)"
4344
}
4445
},
4546
"domain_entity_filters": {

0 commit comments

Comments
 (0)