Skip to content

v8.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 19 Aug 22:19
· 1 commit to master since this release

⚠️⚠️⚠️ BREAKING CHANGE! READ BEFORE UPDATE ⚠️⚠️⚠️

This release is a major one and it is a breaking change.

Previously, instantiating the HomeAssistantJavaScriptTemplates class, when the renderer was resolved, a WebSocket subscription was created to receive entity changes and be able to re-render the templates if any of the entity changed. The issue with this approach is that any client using the package and instantianting the class, will automatically create the aformentioned subscription. In some plugins, JavaScript templates is an optional feature, the user can use them or not (e.g. in custom-sidebar or kiosk-mode). So in the case that the configuration doesn't contain any JavaScript template, there is no need to create the WebSocket subscription.

Starting in this version, if one want's to start the WebSocket subscription to make the templates reactive, one needs to call the public init method.

New methods

init

Initializes the subscriptions for changes. If this method is not called, calls to trackTemplate will execute the renderingFunction only when it is called and not during URL, language or entities changes. This method returns a promise that will be resolved returning the same renderer when all the subscriptions have been created correctly.

Note

This method cannot be called consecutively. Once called, the stop method must be called first before calling it again. If you call this method consecutively, you will receive an error.

stop

Stops the subscriptions for changes. If this method is called, any tracking set with trackTemplate will stop executing its renderingFunction when there are subscription changes.

Note

This method cannot be called if the init method has not been called first. Trying to call this method without calling the init method will throw an error.

parseTemplate

parseTemplate(
    template: string,
    extras?: {
        variables?: Record<string, unknown>,
        refs?: Record<string, unknown>,
    }
): { result: any, entities: string[] }

This method parses a JavaScript template and return an object containing its result and the entities that were tracked. It needs a string as a parameter. Inside this string you can use several objects and methods. It returns whatever the JavaScript code returns, because of that it is typed as any.

Note

This method accepts an optional second parameter with an object. In this object it is possible to send a variables object, containing extra variables that will be appended to the global variables and a refs object, containing extra refs variables. The extra refs variables will be appended to the global ones, making them available even in templates that were declared before the call to this method. You need to be aware, that if a ref variable already exists, sending it again in this method will override it.

New property

subscribed (only getter)

Returns if the renderer has been subscribed (the init method has been called and the stop method has not been called after that).


🚀 Features

🛠 Fixes

🔧 Refactorings

⚙️ Configuration

🧩 Dependencies

  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • [Dependencies]: Bump the dependencies-dev group with 3 updates
  • [Dependencies]: Bump @types/node from 26.0.0 to 26.0.1 in the dependencies-dev group
  • [Dependencies]: Bump @types/node from 26.0.1 to 26.1.0 in the dependencies-dev group
  • Multiple config changes
  • Solve vulnerabilities through pnpm overrides
  • Update pnpm to version 11.15.0
  • [Dependencies]: Bump ts-jest from 29.4.11 to 29.4.12 in the dependencies-dev group
  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • [Dependencies]: Bump the dependencies-dev group with 2 updates
  • Solve vulnerabilities through pnpm overrides

🧪 Tests

📦 Other