Skip to content

Commit

Permalink
Skip host selection if precisely one was found, make hobby profile fi…
Browse files Browse the repository at this point in the history
…rst and default in list, add link to niko connected services page and add Dutch translations
  • Loading branch information
fiva authored and fiva committed Nov 23, 2020
1 parent 6a4473a commit ea2812f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
34 changes: 22 additions & 12 deletions custom_components/nhc2/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def async_step_user(self, user_input=None):

if check > 0:
self._errors["base"] = ("login_check_fail_%d" % check)
return await self._show_user_config_form(selected_coco=self._selected_coco)
return await self._show_user_config_form()

return self.async_create_entry(
title=user_name + ' (' + self._selected_coco[1].replace(':', '') + ')',
Expand All @@ -78,30 +78,36 @@ async def async_step_user(self, user_input=None):
self._all_cocos = await disc.get_all_profiles()
for coco in self._all_cocos:
if coco[2] is not None:
coco[2].append({
coco[2].insert(0, {
'Uuid': 'hobby',
'Name': 'hobby',
'Type': 'hobby'
})
if self._all_cocos is None or len(self._all_cocos) == 0:
return self.async_abort(reason="no_controller_found")

return await self._show_host_config_form(
self._all_cocos)
found_coco_count = len(self._all_cocos) if self._all_cocos else 0
# If there is only one controller, we continue to the next step
if found_coco_count == 1:
self._selected_coco = self._all_cocos[0]
return await self._show_user_config_form()

if found_coco_count > 1:
return await self._show_host_config_form()

return self.async_abort(reason="no_controller_found")

async def async_step_host(self, user_input=None):
self._errors = {}
_LOGGER.debug(self.hass.config_entries.async_entries(DOMAIN))

self._selected_coco = \
list(filter(lambda x: x[0] == user_input[CONF_HOST] or x[3] == user_input[CONF_HOST], self._all_cocos))[0]
return await self._show_user_config_form(self._selected_coco)
return await self._show_user_config_form()

async def _show_host_config_form(self, all_cocos):
async def _show_host_config_form(self):
"""Show the configuration form to edit NHC2 data."""
host_listing = {}
first = None
for i, x in enumerate(all_cocos):
for i, x in enumerate(self._all_cocos):
dkey = x[0] if x[3] is None else x[3]
host_listing[dkey] = [x[3] + ' (' + x[0] + ')']
if i == 0:
Expand All @@ -114,19 +120,23 @@ async def _show_host_config_form(self, all_cocos):
}),
)

async def _show_user_config_form(self, selected_coco=None):
async def _show_user_config_form(self):
"""Show the configuration form to edit NHC2 data."""
profile_listing = {}
profiles = selected_coco[2]
profiles = self._selected_coco[2]
first = None
for i, x in enumerate(profiles):
dkey = x.get('Uuid')
profile_listing[dkey] = x.get('Name') + ' (' + x.get('Uuid') + ')'
profile_listing[dkey] = x.get('Name')
if i == 0:
first = dkey
return self.async_show_form(
step_id='user',
errors=self._errors,
description_placeholders={
"host": self._selected_coco[3] if self._selected_coco[3] is not None else self._selected_coco[0],
"address": self._selected_coco[1]
},
data_schema=vol.Schema({
vol.Required(CONF_USERNAME, default=first): vol.In(profile_listing),
vol.Required(CONF_PASSWORD, default=None): str,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nhc2/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"step": {
"user": {
"description": "Select the profile you wish to use. Profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.",
"description": "Configuring controller {host} ({address}).\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.",
"title": "Connect to your Niko Connected Controller II",
"data": {
"username": "Profile",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nhc2/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"step": {
"user": {
"description": "Select the profile you wish to use. Profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens. To use the hobby profile, you should obtain a password from the Niko website, by adding the 'Niko Hobby API' to your connected services.",
"description": "Configuring controller {host} ({address}).\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.",
"title": "Connect to your Niko Connected Controller II",
"data": {
"username": "Profile",
Expand Down
32 changes: 32 additions & 0 deletions custom_components/nhc2/translations/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"config": {
"step": {
"user": {
"description": "Configureren controller {host} ({address}).\n Een optie is het activeren van de 'Niko Hobby API' op de Geconnecteerde services pagina: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview of je gebruikt een touchscreen profiel. Touchsceen profielen kunnen aangemaakt worden in de 'Niko Home Control programming software' onder Dashboard > Touchscreens",
"title": "Verbinden met je Niko Connected Controller II",
"data": {
"username": "Profiel",
"password": "Wachtwoord",
"switches_as_lights": "Importeer schakelaars (relais) als lichten"
}
},
"host": {
"description": "Als er geen hostnaam (alleen IP) wordt weergegeven, moet deze statisch zijn.",
"title": "Kies een Niko Connected Controller II",
"data": {
"host": "Controller"
}
}
},
"abort": {
"single_instance_allowed": "Controller en profiel reeds toegevoegd."
},
"error": {
"login_check_fail_1": "Verbinding geweigerd - onjuiste protocolversie",
"login_check_fail_2": "Verbinding geweigerd - ongeldige client-ID",
"login_check_fail_3": "Verbinding geweigerd - server niet beschikbaar",
"login_check_fail_4": "Verbinding geweigerd - onjuiste gebruikersnaam of wachtwoord",
"login_check_fail_5": "Verbinding geweigerd - niet geautoriseerd"
}
}
}

0 comments on commit ea2812f

Please sign in to comment.