Skip to content

Commit db9c03a

Browse files
authored
Merge pull request #50 from Darkdragon14/feat/default-token-presets
feat: add token creation defaults for user and dashboard
2 parents 1991a0c + 6c35a9e commit db9c03a

File tree

12 files changed

+188
-21
lines changed

12 files changed

+188
-21
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ To install Guest Mode using [HACS](https://hacs.xyz/):
3333
|**Path for Admin UI**|Custom URL path for accessing the admin interface|No|`/guest-mode`|
3434
|**Login Path**|Custom URL path for guest to access the login page|No|`/guest-mode/login`|
3535
|**Copy link directly (skips sharing)**|If checked, clicking the share button will copy the link directly to the clipboard instead of opening the native share dialog.|No|Unchecked|
36+
|**Default User Name** (`default_user`)|Preselects the user when creating a token. This matches the Home Assistant user's **Name** field.|No|Empty|
37+
|**Default Dashboard/View Path** (`default_dashboard`)|Preselects dashboard or dashboard view when creating a token. Use `dashboard` or `dashboard/view` (examples: `lovelace-guest`, `lovelace-guest/entry`) and do not include a leading slash.|No|Empty|
3638

3739

3840
# Difference with the fork

custom_components/ha_guest_mode/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from homeassistant.core import HomeAssistant
88
from homeassistant.helpers.typing import ConfigType
99
from homeassistant.config_entries import ConfigEntry
10-
from homeassistant.components import websocket_api
10+
from homeassistant.components import frontend, websocket_api
1111
from homeassistant.components.panel_custom import async_register_panel
1212
from homeassistant.helpers import config_validation as cv
1313

14-
from .websocketCommands import list_users, list_groups, create_token, delete_token, get_path_to_login, get_urls, get_panels, get_copy_link_mode
14+
from .websocketCommands import list_users, list_groups, create_token, delete_token, get_path_to_login, get_urls, get_panels, get_copy_link_mode, get_token_defaults
1515
from .validateTokenView import ValidateTokenView
1616
from .keyManager import KeyManager
1717
from .const import DOMAIN, DATABASE, DEST_PATH_SCRIPT_JS, LEGACY_DATABASE, SOURCE_PATH_SCRIPT_JS, SCRIPT_JS
@@ -54,6 +54,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
5454
websocket_api.async_register_command(hass, get_urls)
5555
websocket_api.async_register_command(hass, get_panels)
5656
websocket_api.async_register_command(hass, get_copy_link_mode)
57+
websocket_api.async_register_command(hass, get_token_defaults)
5758

5859
key_manager = KeyManager()
5960
await key_manager.load_or_generate_key()
@@ -115,6 +116,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
115116
hass.data.setdefault(DOMAIN, {})
116117

117118
hass.data["copy_link_mode"] = config_entry.options.get("copy_link_mode", config_entry.data.get("copy_link_mode", False))
119+
hass.data["default_user"] = config_entry.options.get("default_user", config_entry.data.get("default_user", ""))
120+
hass.data["default_dashboard"] = config_entry.options.get("default_dashboard", config_entry.data.get("default_dashboard", ""))
118121

119122
get_path_to_login = config_entry.options.get("login_path", config_entry.data.get("login_path", "/guest-mode/login"))
120123
if not get_path_to_login.startswith('/'):
@@ -129,7 +132,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
129132

130133
panels = hass.data.get("frontend_panels", {})
131134
if path in panels:
132-
hass.components.frontend.async_remove_panel(path)
135+
frontend.async_remove_panel(hass, path)
133136

134137
hass.async_create_task(
135138
async_register_panel(
@@ -157,7 +160,9 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
157160

158161
panels = hass.data.get("frontend_panels", {})
159162
if path in panels:
160-
hass.components.frontend.async_remove_panel(path)
163+
frontend.async_remove_panel(hass, path)
164+
165+
await hass.config_entries.async_unload_platforms(config_entry, ["image"])
161166
return True
162167

163168
async def async_copy_file(source_path, dest_path):

custom_components/ha_guest_mode/config_flow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ async def async_step_user(self, user_input=None):
2929
vol.Optional("path_to_admin_ui", default="/guest-mode"): str,
3030
vol.Optional("login_path", default="/guest-mode/login"):str,
3131
vol.Optional("copy_link_mode", default=False): bool,
32+
vol.Optional("default_user", default=""): str,
33+
vol.Optional("default_dashboard", default=""): str,
3234
}),
3335
)
3436

3537
@staticmethod
3638
@callback
3739
def async_get_options_flow(config_entry: config_entries.ConfigEntry):
38-
return OptionsFlowHandler()
40+
return OptionsFlowHandler()

custom_components/ha_guest_mode/options_flow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ async def async_step_init(self, user_input=None):
2323
path = self.config_entry.options.get("path_to_admin_ui", self.config_entry.data.get("path_to_admin_ui", "/guest-mode"))
2424
login_path = self.config_entry.options.get("login_path", self.config_entry.data.get("login_path", "/guest-mode/login"))
2525
copy_link = self.config_entry.options.get("copy_link_mode", self.config_entry.data.get("copy_link_mode", False))
26+
default_user = self.config_entry.options.get("default_user", self.config_entry.data.get("default_user", ""))
27+
default_dashboard = self.config_entry.options.get("default_dashboard", self.config_entry.data.get("default_dashboard", ""))
2628
return self.async_show_form(
2729
step_id="init",
2830
data_schema=vol.Schema({
@@ -31,5 +33,7 @@ async def async_step_init(self, user_input=None):
3133
vol.Optional("path_to_admin_ui", default=path): str,
3234
vol.Optional("login_path", default=login_path): str,
3335
vol.Optional("copy_link_mode", default=copy_link): bool,
36+
vol.Optional("default_user", default=default_user): str,
37+
vol.Optional("default_dashboard", default=default_dashboard): str,
3438
}),
35-
)
39+
)

custom_components/ha_guest_mode/translations/de.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Tab-Name",
88
"path_to_admin_ui": "Pfad zur Admin-Oberfläche",
99
"login_path": "Gast-Login-Pfad",
10-
"copy_link_mode": "Link direkt kopieren (überspringt das Teilen)"
10+
"copy_link_mode": "Link direkt kopieren (überspringt das Teilen)",
11+
"default_user": "Standard-Benutzername",
12+
"default_dashboard": "Standard-Dashboard-/View-Pfad"
13+
},
14+
"data_description": {
15+
"default_user": "Entspricht dem Feld Name des Home-Assistant-Benutzers.",
16+
"default_dashboard": "Verwenden Sie dashboard oder dashboard/view (z. B. lovelace-guest oder lovelace-guest/eingang). Keinen führenden Schrägstrich angeben."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Tab-Name",
2531
"path_to_admin_ui": "Pfad zur Admin-Oberfläche",
2632
"login_path": "Gast-Login-Pfad",
27-
"copy_link_mode": "Link direkt kopieren (überspringt das Teilen)"
33+
"copy_link_mode": "Link direkt kopieren (überspringt das Teilen)",
34+
"default_user": "Standard-Benutzername",
35+
"default_dashboard": "Standard-Dashboard-/View-Pfad"
36+
},
37+
"data_description": {
38+
"default_user": "Entspricht dem Feld Name des Home-Assistant-Benutzers.",
39+
"default_dashboard": "Verwenden Sie dashboard oder dashboard/view (z. B. lovelace-guest oder lovelace-guest/eingang). Keinen führenden Schrägstrich angeben."
2840
}
2941
}
3042
}

custom_components/ha_guest_mode/translations/en.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Tab Name",
88
"path_to_admin_ui": "Path to Admin Interface",
99
"login_path": "Guest Login Path",
10-
"copy_link_mode": "Copy link directly (skips sharing)"
10+
"copy_link_mode": "Copy link directly (skips sharing)",
11+
"default_user": "Default User Name",
12+
"default_dashboard": "Default Dashboard/View Path"
13+
},
14+
"data_description": {
15+
"default_user": "Matches the Home Assistant user's Name field.",
16+
"default_dashboard": "Use dashboard or dashboard/view (example: lovelace-guest or lovelace-guest/entry). Do not include a leading slash."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Tab Name",
2531
"path_to_admin_ui": "Path to Admin Interface",
2632
"login_path": "Guest Login Path",
27-
"copy_link_mode": "Copy link directly (skips sharing)"
33+
"copy_link_mode": "Copy link directly (skips sharing)",
34+
"default_user": "Default User Name",
35+
"default_dashboard": "Default Dashboard/View Path"
36+
},
37+
"data_description": {
38+
"default_user": "Matches the Home Assistant user's Name field.",
39+
"default_dashboard": "Use dashboard or dashboard/view (example: lovelace-guest or lovelace-guest/entry). Do not include a leading slash."
2840
}
2941
}
3042
}

custom_components/ha_guest_mode/translations/es.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Nombre de pestaña",
88
"path_to_admin_ui": "Ruta a la interfaz de administración",
99
"login_path": "Ruta de inicio de sesión de invitado",
10-
"copy_link_mode": "Copiar enlace directamente (omite compartir)"
10+
"copy_link_mode": "Copiar enlace directamente (omite compartir)",
11+
"default_user": "Nombre de usuario predeterminado",
12+
"default_dashboard": "Ruta predeterminada de tablero/vista"
13+
},
14+
"data_description": {
15+
"default_user": "Coincide con el campo Nombre del usuario de Home Assistant.",
16+
"default_dashboard": "Use dashboard o dashboard/view (por ejemplo: lovelace-guest o lovelace-guest/entrada). No incluya la barra inicial."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Nombre de pestaña",
2531
"path_to_admin_ui": "Ruta a la interfaz de administración",
2632
"login_path": "Ruta de inicio de sesión de invitado",
27-
"copy_link_mode": "Copiar enlace directamente (omite compartir)"
33+
"copy_link_mode": "Copiar enlace directamente (omite compartir)",
34+
"default_user": "Nombre de usuario predeterminado",
35+
"default_dashboard": "Ruta predeterminada de tablero/vista"
36+
},
37+
"data_description": {
38+
"default_user": "Coincide con el campo Nombre del usuario de Home Assistant.",
39+
"default_dashboard": "Use dashboard o dashboard/view (por ejemplo: lovelace-guest o lovelace-guest/entrada). No incluya la barra inicial."
2840
}
2941
}
3042
}

custom_components/ha_guest_mode/translations/fr.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Nom de l'onglet",
88
"path_to_admin_ui": "Chemin vers l'interface d'administration",
99
"login_path": "Chemin de connexion des invités",
10-
"copy_link_mode": "Copier le lien directement (ignore le partage)"
10+
"copy_link_mode": "Copier le lien directement (ignore le partage)",
11+
"default_user": "Nom de l'utilisateur par défaut",
12+
"default_dashboard": "Chemin tableau de bord/vue par défaut"
13+
},
14+
"data_description": {
15+
"default_user": "Correspond au champ Nom de l'utilisateur Home Assistant.",
16+
"default_dashboard": "Utilisez dashboard ou dashboard/view (exemple : lovelace-guest ou lovelace-guest/entree). N'incluez pas de slash initial."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Nom de l'onglet",
2531
"path_to_admin_ui": "Chemin vers l'interface d'administration",
2632
"login_path": "Chemin de connexion des invités",
27-
"copy_link_mode": "Copier le lien directement (ignore le partage)"
33+
"copy_link_mode": "Copier le lien directement (ignore le partage)",
34+
"default_user": "Nom de l'utilisateur par défaut",
35+
"default_dashboard": "Chemin tableau de bord/vue par défaut"
36+
},
37+
"data_description": {
38+
"default_user": "Correspond au champ Nom de l'utilisateur Home Assistant.",
39+
"default_dashboard": "Utilisez dashboard ou dashboard/view (exemple : lovelace-guest ou lovelace-guest/entree). N'incluez pas de slash initial."
2840
}
2941
}
3042
}

custom_components/ha_guest_mode/translations/it.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Nome della scheda",
88
"path_to_admin_ui": "Percorso all'interfaccia amministrativa",
99
"login_path": "Percorso di accesso ospite",
10-
"copy_link_mode": "Copia il link direttamente (salta la condivisione)"
10+
"copy_link_mode": "Copia il link direttamente (salta la condivisione)",
11+
"default_user": "Nome utente predefinito",
12+
"default_dashboard": "Percorso predefinito dashboard/vista"
13+
},
14+
"data_description": {
15+
"default_user": "Corrisponde al campo Nome dell'utente di Home Assistant.",
16+
"default_dashboard": "Usa dashboard o dashboard/view (esempio: lovelace-guest o lovelace-guest/ingresso). Non includere la barra iniziale."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Nome della scheda",
2531
"path_to_admin_ui": "Percorso all'interfaccia amministrativa",
2632
"login_path": "Percorso di accesso ospite",
27-
"copy_link_mode": "Copia il link direttamente (salta la condivisione)"
33+
"copy_link_mode": "Copia il link direttamente (salta la condivisione)",
34+
"default_user": "Nome utente predefinito",
35+
"default_dashboard": "Percorso predefinito dashboard/vista"
36+
},
37+
"data_description": {
38+
"default_user": "Corrisponde al campo Nome dell'utente di Home Assistant.",
39+
"default_dashboard": "Usa dashboard o dashboard/view (esempio: lovelace-guest o lovelace-guest/ingresso). Non includere la barra iniziale."
2840
}
2941
}
3042
}

custom_components/ha_guest_mode/translations/nl.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"tab_name": "Tab naam",
88
"path_to_admin_ui": "Pad naar admin-interface",
99
"login_path": "Gast login-pad",
10-
"copy_link_mode": "Kopieer de link direct (slaat delen over)"
10+
"copy_link_mode": "Kopieer de link direct (slaat delen over)",
11+
"default_user": "Standaard gebruikersnaam",
12+
"default_dashboard": "Standaard dashboard-/viewpad"
13+
},
14+
"data_description": {
15+
"default_user": "Komt overeen met het veld Naam van de Home Assistant-gebruiker.",
16+
"default_dashboard": "Gebruik dashboard of dashboard/view (bijv. lovelace-guest of lovelace-guest/entree). Voeg geen voorloopslash toe."
1117
}
1218
}
1319
},
@@ -24,7 +30,13 @@
2430
"tab_name": "Tab naam",
2531
"path_to_admin_ui": "Pad naar admin-interface",
2632
"login_path": "Gast login-pad",
27-
"copy_link_mode": "Kopieer de link direct (slaat delen over)"
33+
"copy_link_mode": "Kopieer de link direct (slaat delen over)",
34+
"default_user": "Standaard gebruikersnaam",
35+
"default_dashboard": "Standaard dashboard-/viewpad"
36+
},
37+
"data_description": {
38+
"default_user": "Komt overeen met het veld Naam van de Home Assistant-gebruiker.",
39+
"default_dashboard": "Gebruik dashboard of dashboard/view (bijv. lovelace-guest of lovelace-guest/entree). Voeg geen voorloopslash toe."
2840
}
2941
}
3042
}

0 commit comments

Comments
 (0)