Skip to content

Commit 98b0b04

Browse files
authored
Fix broken options flow (#113)
Trying to access self.hass in the constructor of an options flow does not work as it has not been set yet. This change moves that code to where it's actually used.
1 parent 0700722 commit 98b0b04

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

custom_components/remote_homeassistant/config_flow.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ def __init__(self, config_entry):
188188
self.filters = None
189189
self.events = None
190190
self.options = None
191-
self.remote = self.hass.data[DOMAIN][self.config_entry.entry_id][
192-
CONF_REMOTE_CONNECTION
193-
]
194191

195192
async def async_step_init(self, user_input=None):
196193
"""Manage basic options."""
@@ -201,6 +198,10 @@ async def async_step_init(self, user_input=None):
201198
domains, _ = self._domains_and_entities()
202199
domains = set(domains + self.config_entry.options.get(CONF_LOAD_COMPONENTS, []))
203200

201+
remote = self.hass.data[DOMAIN][self.config_entry.entry_id][
202+
CONF_REMOTE_CONNECTION
203+
]
204+
204205
return self.async_show_form(
205206
step_id="init",
206207
data_schema=vol.Schema(
@@ -223,7 +224,7 @@ async def async_step_init(self, user_input=None):
223224
vol.Optional(
224225
CONF_SERVICES,
225226
default=self._default(CONF_SERVICES),
226-
): cv.multi_select(self.remote.proxy_services.services),
227+
): cv.multi_select(remote.proxy_services.services),
227228
}
228229
),
229230
)

custom_components/remote_homeassistant/proxy_services.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ def __init__(self, hass, entry, remote):
2323
@property
2424
def services(self):
2525
"""Return list of service names."""
26-
services = []
26+
result = []
2727
for domain, services in self.remote_services.items():
2828
for service in services.keys():
29-
services.append(f"{domain}.{service}")
30-
return sorted(services)
29+
result.append(f"{domain}.{service}")
30+
return sorted(result)
3131

3232
async def load(self):
3333
"""Call to make initial registration of services."""
@@ -55,7 +55,7 @@ async def _async_got_services(self, message):
5555
return
5656

5757
description_cache = self.hass.data[SERVICE_DESCRIPTION_CACHE]
58-
for service in self.entry.options[CONF_SERVICES]:
58+
for service in self.entry.options.get(CONF_SERVICES, []):
5959
domain, service_name = service.split(".")
6060
service = service_prefix + service_name
6161

0 commit comments

Comments
 (0)