Skip to content

Commit

Permalink
Merge pull request #78 from peribeir/peribeir/issue73
Browse files Browse the repository at this point in the history
Integration fails on bridge with password protection
  • Loading branch information
peribeir authored Jun 8, 2023
2 parents 2afc16d + aeb27de commit cab08c9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 48 deletions.
8 changes: 7 additions & 1 deletion custom_components/rademacher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry.data[CONF_HOST],
entry.data[CONF_PASSWORD] if CONF_PASSWORD in entry.data else "",
)
manager = await HomePilotManager.async_build_manager(api)
try:
manager = await HomePilotManager.async_build_manager(api)
except AuthError as err:
# Raising ConfigEntryAuthFailed will cancel future updates
# and start a config flow with SOURCE_REAUTH (async_step_reauth)
raise ConfigEntryAuthFailed from err

_LOGGER.info("Manager instance created, found %s devices", len(manager.devices))
_LOGGER.debug("Device IDs: %s", list(manager.devices))

Expand Down
48 changes: 48 additions & 0 deletions custom_components/rademacher/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import socket
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries, exceptions, data_entry_flow
Expand Down Expand Up @@ -33,6 +34,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
host: str = ""
password: str = ""
reauth_entry: ConfigEntry | None = None
exclude_devices: list[str] = []
ternary_contact_sensors: list[str] = []

Expand Down Expand Up @@ -75,6 +77,44 @@ async def async_step_config(self, user_input=None):
errors=errors,
)

async def async_step_reauth(self, user_input=None):
self.reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
self.host=self.reauth_entry.data[CONF_HOST]
self.password=self.reauth_entry.data[CONF_PASSWORD]
errors={}

try:
conn_test = await HomePilotApi.test_connection(user_input[CONF_HOST])
if conn_test == "ok":
data = {
CONF_HOST: self.host,
CONF_PASSWORD: "",
}
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")

await HomePilotApi.test_auth(self.host, self.password)
return self.async_abort(reason="reauth_successful")
except CannotConnect:
_LOGGER.warning("Connect error (IP %s)", self.host)
errors["base"] = "cannot_connect"
except InvalidHost:
_LOGGER.warning("Invalid Host (IP %s)", self.host)
errors["base"] = "cannot_connect"
except AuthError:
_LOGGER.warning("Wrong Password (IP %s)", self.host)
errors["base"] = "auth_error"
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception", exc_info=True)
errors["base"] = "unknown"

return self.async_show_form(
step_id="user_password", data_schema=DATA_SCHEMA_PASSWORD, errors=errors
)

async def async_step_user_password(self, user_input=None):
errors = {}
if user_input is not None and CONF_PASSWORD in user_input:
Expand All @@ -85,6 +125,14 @@ async def async_step_user_password(self, user_input=None):
"Password correct (IP %s), creating entries",
self.host,
)
if self.reauth_entry:
data = {
CONF_HOST: self.host,
CONF_PASSWORD: self.password,
}
self.hass.config_entries.async_update_entry(self.reauth_entry, data=data)
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")
return await self.async_step_config(user_input=user_input)
except CannotConnect:
_LOGGER.warning("Connect error (IP %s)", self.host)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/rademacher/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"abort": {
"no_devices_found": "Es wurden keine Ger\u00e4te gefunden.",
"cannot_connect": "Fehler bei Verbindung zur Bridge. Bitte stelle sicher, dass die Bridge im Netzwerk verbunden und Hostname/IP korrekt ist."
"cannot_connect": "Fehler bei Verbindung zur Bridge. Bitte stelle sicher, dass die Bridge im Netzwerk verbunden und Hostname/IP korrekt ist.",
"reauth_successful": "Die erneute Authentifizierung war erfolgreich."
}
}
}
3 changes: 2 additions & 1 deletion custom_components/rademacher/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"abort": {
"no_devices_found": "No devices were found.",
"cannot_connect": "Error connecting to the bridge. Please verify the bridge is connected to the network, and verify that the Hostname/IP is correct."
"cannot_connect": "Error connecting to the bridge. Please verify the bridge is connected to the network, and verify that the Hostname/IP is correct.",
"reauth_successful": "Reauthentication was successful."
}
}
}
86 changes: 44 additions & 42 deletions custom_components/rademacher/translations/es.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
{
"title": "Rademacher HomePilot",
"options": {
"step": {
"init": {
"title": "Configuración",
"description": "",
"data": {
"exclude": "EXCLUIR dispositivos (marca los dispositivos que NO quieres agregar):",
"sensor_type": "Selecciona los sensores de Contacto con posición inclinada:"
"title": "Rademacher HomePilot",
"options": {
"step": {
"init": {
"title": "Configuración",
"description": "",
"data": {
"exclude": "EXCLUIR dispositivos (marca los dispositivos que NO quieres agregar):",
"sensor_type": "Selecciona los sensores de Contacto con posición inclinada:"
}
}
}
}
},
"config": {
"step": {
"user": {
"title": "Introduce el Hostname/IP del dispositivo Bridge",
"description": "Por favor, escribe el Hostname o dirección IP de tu dispositivo Rademacher Bridge (Start2Smart or HomePilot).",
"data": {
"host": "Hostname/IP"
},
"config": {
"step": {
"user": {
"title": "Introduce el Hostname/IP del dispositivo Bridge",
"description": "Por favor, escribe el Hostname o dirección IP de tu dispositivo Rademacher Bridge (Start2Smart or HomePilot).",
"data": {
"host": "Hostname/IP"
}
},
"user_password": {
"title": "Introducir contraseña",
"description": "Por favor, escribe la contraseña de tu Rademacher Bridge (Start2Smart or HomePilot).",
"data": {
"password": "Contraseña"
}
},
"config": {
"title": "Configuración",
"description": "",
"data": {
"exclude": "EXCLUIR dispositivos (marca los dispositivos que NO quieres agregar):",
"sensor_type": "Selecciona los sensores de Contacto con posición inclinada:"
}
}
},
"user_password": {
"title": "Introducir contraseña",
"description": "Por favor, escribe la contraseña de tu Rademacher Bridge (Start2Smart or HomePilot).",
"data": {
"password": "Contraseña"
}
"error": {
"no_device_selected": "Tienes que seleccionar al menos un dispositivo.",
"cannot_connect": "Error al conectarse al bridge. Por favor, comprueba que el bridge está conectado a la red, y que el Hostname/IP son correctos.",
"auth_error": "Contraseña inválida. Asegúrate de introducir la contraseña correcta.",
"unknown": "Error desconocido."
},
"config": {
"title": "Configuración",
"description": "",
"data": {
"exclude": "EXCLUIR dispositivos (marca los dispositivos que NO quieres agregar):",
"sensor_type": "Selecciona los sensores de Contacto con posición inclinada:"
}
"abort": {
"no_devices_found": "No se han encontrado dispositivos.",
"cannot_connect": "Error al conectarse al bridge. Por favor, comprueba que el bridge está conectado a la red, y que el Hostname/IP son correctos.",
"reauth_successful": "La reautenticación fue exitosa."
}
},
"error": {
"no_device_selected": "Tienes que seleccionar al menos un dispositivo.",
"cannot_connect": "Error al conectarse al bridge. Por favor, comprueba que el bridge está conectado a la red, y que el Hostname/IP son correctos.",
"auth_error": "Contraseña inválida. Asegúrate de introducir la contraseña correcta.",
"unknown": "Error desconocido."
},
"abort": {
"no_devices_found": "No se han encontrado dispositivos.",
"cannot_connect": "Error al conectarse al bridge. Por favor, comprueba que el bridge está conectado a la red, y que el Hostname/IP son correctos."
}
}
}
3 changes: 2 additions & 1 deletion custom_components/rademacher/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"abort": {
"no_devices_found": "Nenhum dispositivo encontrado.",
"cannot_connect": "Erro ao contactar a bridge. Por favor verifique que a bridge est\u00e1 ligada \u00e0 rede, e que o Nome de Servidor / IP provideciado est\u00e1 correto."
"cannot_connect": "Erro ao contactar a bridge. Por favor verifique que a bridge est\u00e1 ligada \u00e0 rede, e que o Nome de Servidor / IP provideciado est\u00e1 correto.",
"reauth_successful": "Re-autentica\u00e7\u00e3o foi bem sucedida."
}
}
}
3 changes: 2 additions & 1 deletion custom_components/rademacher/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"abort": {
"no_devices_found": "Nenhum dispositivo encontrado.",
"cannot_connect": "Erro ao contactar a bridge. Por favor verifique que a bridge est\u00e1 ligada \u00e0 rede, e que o Nome de Servidor / IP provideciado est\u00e1 correto."
"cannot_connect": "Erro ao contactar a bridge. Por favor verifique que a bridge est\u00e1 ligada \u00e0 rede, e que o Nome de Servidor / IP provideciado est\u00e1 correto.",
"reauth_successful": "Re-autentica\u00e7\u00e3o foi bem sucedida."
}
}
}
3 changes: 2 additions & 1 deletion custom_components/rademacher/translations/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"abort": {
"no_devices_found": "Nenašli sa žiadne zariadenia.",
"cannot_connect": "Chyba pri pripájaní k bridge. Skontrolujte, či je bridge pripojený k sieti a či je názov hostiteľa/IP správna."
"cannot_connect": "Chyba pri pripájaní k bridge. Skontrolujte, či je bridge pripojený k sieti a či je názov hostiteľa/IP správna.",
"reauth_successful": "Opätovná autentifikácia bola úspešná."
}
}
}

0 comments on commit cab08c9

Please sign in to comment.