Add support for JavaScript / Jinja templates in the kiosk-mode options #274
+487
−443
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is a major refactoring of the plugin and it changes radically the way of setting
kiosk-mode
options through entities state changes.Removal of
entity_settings
The
entity_settings
andignore_entity_settings
options have been removed.All the options can be booleans or
JavaScript
/Jinja
templatesExcluding
ignore_mobile_settings
andignore_disable_km
, all the options can be set as aJavaScript
or aJinja
template that returns a boolean. If you set the option as a string but it is not a valid template, the library will throw an error. If you set a template and it doesn't return a boolean, the option will be set as false and a warning will be thrown.JavaScript template example:
Jinja template example:
This solves one of the biggest issues that the plugin has: If one wants to configure entity changes for different users or for admins and non-admins the current configuration is not enough because there is a single place to configure entitites changes and it doesn't take into account users or admin privileges. With this new change it is possible to make something like this:
JavaScript templates use Home Assistant Javascript Templates behind the scenes
JavaScript
templates use Home Assistant Javascript Templates for theJavaScript
templating system. To know all the objects, variables and methods available in theJavaScript
templates, consult the proper section in the repository.Jinja templates will have access to client side variables
Inside the Jinja templates you can use some client variables that are very useful:
user_name
: String with the logged user's nameuser_is_admin
: Bolean value than indicates if the logged user is admin or notuser_is_owner
: Bolean value than indicates if the logged user is the owner or notuser_agent
: User agent of the browser in which Home Assistant is being executedAdvantages of using templates for the options
Using templates for the options gives a lot of flexibility and depending on your objectives you can omit the usage of the conditional configs, so when you start to create conditional configurations, ask yourself if it can be achieved with templates. For example:
Can be transformed into a simpler version: