Homekit-panel-card
Homekit-panel-card copied to clipboard
Custom header kiosk mode and unathorized template API error
When using compact header in kiosk mode (hidden header) the template API bugs out with the fetch-with-auth function. When header is visible there's no thrown errors.
Is it just me or can anyone else replicate? 192.168.1.10-1579600841664.log
After some further digging it seams to be an error by using a non administrator user. This makes the template function to error out with the auth.
@acateon yes you need admin rights for the template part i do not yet know a way to do the same thing where you don't need this.
@DBuit If you use the subscribeRenderTemplate method in card-tools instead of parseTemplate this shouldwork whether the user is an admin or not. The difference is that the method fires an event to the handler you provide rather than just returning a result.
In the latest beta of my lovelace-card-templater card I created a wrapper around that function which returns a Promise so you can await it or use then() and error() Here is the function (this would need tweaking slightly as I have card-tools loaded as a Lovelace resource):
parseTemplate(template, variables){
return new Promise((resolve, reject) => {
let unsubRenderTemplate = cardTools.subscribeRenderTemplate(null,
async (result) => {
resolve(result);
},
{template: template, variables: variables,
entity_ids: []});
let unsub = null;
// Catch any errors and unsubscribe
(async () => {
try {
unsub = await unsubRenderTemplate;
await unsub();
} catch (e) {
reject(e.message);
}
})();
});
}
Hi @gadgetchnnel ,
Thank you for shared that code. At the moment you don't set a list of variables used in the template, is that a problem? Or should i expand the configuration to also give all variables?
@DBuit Are you referring to the entity_ids? Those are only needed if you want to override what entity ids it will monitor for changes (rather than it picking this up automatically when it parses the template). Since my wrapper method only calls subscribeRenderTemplate as a one-off, rather than actually subscribing to future updates, they aren't actually needed.
I have the same problem with the template function in the homekit panel card. Strangely enough, the template function does work on the sidebar-card that was also developed by @DBuit.