DBuit / Homekit-panel-card

Homekit panel card for home assistant
MIT License
304 stars 54 forks source link

Custom header kiosk mode and unathorized template API error #15

Open acateon opened 4 years ago

acateon commented 4 years ago

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

acateon commented 4 years ago

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.

DBuit commented 4 years ago

@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.

gadgetchnnel commented 4 years ago

@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);
                }
            })();
        });
      }
DBuit commented 4 years ago

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?

gadgetchnnel commented 4 years ago

@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.

Denow commented 3 years ago

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.