Can the current users name / credentials be passed in from frontend to backend functions.
Let’s use an Alarm Control Panel as an example.
EDIT: In my custom integration I extend this Entity to create a custom alarm control panel. Whether a keypad is displayed or not is part of the backend and determined by
code_format as defined here in the Alarm Control Panel Entity page.
Within the “alarm control panel” integration I’d like to use the current user to determine whether to show the numeric keypad or not. This way a tablet can be used in a house hallway showing the keypad and a user with their mobile phone (as a different user in Home Assistant) would not get the keypad.
Either the ability to get the current logged in user in the backend or the current user passed across in the functions:
I feel sure that could be useful for other integration as well.
If there is a way of achieving this that I haven’t spotted then please let me know.
Visibility setting in the dashboard tabs.
Hi and thanks for the suggestion but I don’t think that would work.
Even if I created different dashboards and gave different users visibility access to the them, the backend i.e. the integration itself would not differentiate between them. Whether a keypad is displayed or not is part of the backend and determined by
code_format as defined here in the Alarm Control Panel Entity page. What I need is the “current logged in user” passed across in to that function call to determine if that user should get a keypad or not.
I am assuming you mean manual alarm panel
Which needs a dashboard card…
on the other account there is no panel.
Perhaps you mean some other integration though.
I can see now that it could mean the manual alarm integration and it doesn’t (or perhaps could do as I believe this also derives itself from the base Entity). What you suggest for this would I think work yes. I’m so sorry and I’ve edited the first post to add this to make it clear.
EDIT: In my custom integration I extend this Entity to create a custom alarm control panel.
Ahh yeah that’s a bit different if it forces itself onto a dashboard?
Where is the Alarm Control Panel entity page?
Needs an admin mode or similar.
the context object in automation provides this information. You can use a template to determine the user that made the request/call/service/etc.
Thanks for replying, so is this something that I’d need to do in the frontend first and how could that influence the return of the code_format here. Or is it something I can get in the integration python and if so can you help me out with how. Can I get the context in the backend python somehow?
The information I available in automations and scripts. Without needing python
Ah OK, but you need python to do this within a custom integration, so in my opinion it is still a valid WTH.
No you don’t. Did you read my last message? I said you don’t need python for this.
Oh sorry, so how would I achieve that using automations and scripts, perhaps you could help me make a start at these. Would they override the backend code_format setting somehow?
So after 4 weeks I still haven’t figured this out, can anyone help please?
I think that I can figure out a way to use a template to determine the user but I can’t figure out how to use that to either show or hide the keypad that the alarm panel integration displays. This also interacts with the integration itself so I’m struggling with it.
Any detailed help would be appreciated.
It is all good that we have “Users” defined in Home Assistant but we can’t take full advantage of that in the integrations. For example, if one of the security permissions was to allow a user to bypass the use of the keypad ot force a user to use the keypad then I could programme that in to integration backend.
What I am thinking here is customised security permissions for a user for each entity. At the moment we can do the following in an integration but I’m not sure where these are set in Home Assistant itself.
user = await hass.auth.async_get_user(call.context.user_id)
if user is None:
reg = entity_registry.async_get(hass)
authorized = False
for entity in reg.entities.values():
if entity.platform != domain:
if user.permissions.check_entity(entity.entity_id, POLICY_CONTROL):
authorized = True
if not authorized: