Skip to content

Commit 8f0e8f5

Browse files
committed
Update dependencies and clean up
Use lit 2.8.0 to match HA frontend version. Fixes iantrich#91, Closes iantrich#123, Closes iantrich#128, Closes iantrich#129, Closes iantrich#135
1 parent 6bb3e92 commit 8f0e8f5

11 files changed

Lines changed: 586 additions & 1912 deletions

.eslintrc.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ name: "Build"
22

33
on:
44
push:
5-
branches:
5+
branches:
66
- master
77
pull_request:
8-
branches:
8+
branches:
99
- master
1010

1111
jobs:
1212
build:
13-
name: Test build
13+
name: Build
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v1
16+
- uses: actions/checkout@v4
1717
- name: Build
1818
run: |
19-
npm install
19+
yarn install
2020
npm run build

.github/workflows/release.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ jobs:
99
name: Prepare release
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
12+
- uses: actions/checkout@v4
1313

14-
# Build
15-
- name: Build the file
14+
- name: Build
1615
run: |
1716
cd /home/runner/work/config-template-card/config-template-card
18-
npm install
17+
yarn install
1918
npm run build
2019
21-
# Upload build file to the releas as an asset.
22-
- name: Upload zip to release
23-
uses: svenstaro/upload-release-action@v1-release
24-
20+
- name: Upload as release
21+
uses: svenstaro/upload-release-action@v2
2522
with:
2623
repo_token: ${{ secrets.GITHUB_TOKEN }}
2724
file: /home/runner/work/config-template-card/config-template-card/dist/config-template-card.js

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @ts-check
2+
3+
import js from '@eslint/js';
4+
import ts from 'typescript-eslint';
5+
import globals from 'globals';
6+
7+
export default ts.config(
8+
js.configs.recommended,
9+
ts.configs.recommended,
10+
{
11+
rules: {
12+
'@typescript-eslint/no-explicit-any': 'off',
13+
},
14+
languageOptions: {
15+
sourceType: 'module', // Allows for the use of imports
16+
parserOptions: {
17+
tsconfigRootDir: import.meta.dirname,
18+
projectService: true, // TypeScript type checking service
19+
},
20+
},
21+
}
22+
);

package.json

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,18 @@
1515
"author": "Ian Richardson <iantrich@gmail.com>",
1616
"license": "MIT",
1717
"dependencies": {
18-
"custom-card-helpers": "^1.7.2",
18+
"custom-card-helpers": "^1.9.0",
1919
"deep-clone-simple": "^1.1.1",
20-
"lit": "^3.2.1"
20+
"lit": "^2.8.0"
2121
},
2222
"devDependencies": {
23-
"@babel/core": "^7.15.0",
24-
"@babel/plugin-proposal-class-properties": "^7.14.5",
25-
"@babel/plugin-proposal-decorators": "^7.14.5",
26-
"@rollup/plugin-babel": "^6.0.4",
27-
"@rollup/plugin-commonjs": "^28.0.0",
28-
"@rollup/plugin-json": "^6.1.0",
23+
"rollup": "^4.24.3",
2924
"@rollup/plugin-node-resolve": "^15.3.0",
30-
"@rollup/plugin-terser": "^0.4.4",
31-
"@typescript-eslint/eslint-plugin": "^8.8.1",
32-
"@typescript-eslint/parser": "^8.8.1",
33-
"eslint": "^8.57.1",
34-
"eslint-config-prettier": "^8.3.0",
35-
"eslint-plugin-import": "^2.24.0",
36-
"eslint-plugin-prettier": "^4.0.0",
37-
"prettier": "^3.3.3",
38-
"rollup": "^4.24.0",
39-
"rollup-plugin-serve": "^1.1.1",
4025
"rollup-plugin-typescript2": "^0.36.0",
41-
"typescript": "~5.5.0"
26+
"typescript": "~5.7.3",
27+
"rollup-plugin-serve": "^3.0.0",
28+
"eslint": "^9.20.1",
29+
"typescript-eslint": "^8.24.0"
4230
},
4331
"scripts": {
4432
"start": "rollup -c rollup.config.dev.mjs --watch",

rollup.config.dev.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ export default {
2121
},
2222
}),
2323
], treeshake: false,
24+
moduleContext: {
25+
// intl-utils is deprecated but still used by custom-card-helpers.
26+
// Until it is removed from custom-card-helpers, silence a Rollup warning related to it:
27+
// https://rollupjs.org/troubleshooting/#error-this-is-undefined
28+
'node_modules/@formatjs/intl-utils/lib/src/diff.js': 'window',
29+
'node_modules/@formatjs/intl-utils/lib/src/resolve-locale.js': 'window',
30+
},
2431
};

rollup.config.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import resolve from "@rollup/plugin-node-resolve";
2-
import typescript from "rollup-plugin-typescript2";
1+
import resolve from '@rollup/plugin-node-resolve';
2+
import typescript from 'rollup-plugin-typescript2';
33

44
export default {
5-
input: ["src/config-template-card.ts"],
5+
input: ['src/config-template-card.ts'],
66
output: {
7-
dir: "./dist",
8-
format: "es"
7+
dir: './dist',
8+
format: 'es',
99
},
1010
plugins: [
1111
resolve(),
1212
typescript(),
1313
], treeshake: false,
14+
moduleContext: {
15+
// intl-utils is deprecated but still used by custom-card-helpers.
16+
// Until it is removed from custom-card-helpers, silence a Rollup warning related to it:
17+
// https://rollupjs.org/troubleshooting/#error-this-is-undefined
18+
'node_modules/@formatjs/intl-utils/lib/src/diff.js': 'window',
19+
'node_modules/@formatjs/intl-utils/lib/src/resolve-locale.js': 'window',
20+
},
1421
};

src/config-template-card.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { LitElement, html, TemplateResult, PropertyValues } from 'lit-element';
2-
import { customElement, property, state } from 'lit-element/decorators.js';
1+
import { LitElement, html, TemplateResult, PropertyValues } from 'lit';
2+
import { customElement, property, state } from 'lit/decorators.js';
33
import deepClone from 'deep-clone-simple';
44
import { computeCardSize, HomeAssistant, LovelaceCard } from 'custom-card-helpers';
55

@@ -17,7 +17,6 @@ console.info(
1717
export class ConfigTemplateCard extends LitElement {
1818
@property({ attribute: false }) public hass?: HomeAssistant;
1919
@state() private _config?: ConfigTemplateConfig;
20-
/* eslint-disable @typescript-eslint/no-explicit-any */
2120
@state() private _helpers?: any;
2221
private _initialized = false;
2322

@@ -68,7 +67,6 @@ export class ConfigTemplateCard extends LitElement {
6867
}
6968

7069
private getLovelaceConfig() {
71-
/* eslint-disable @typescript-eslint/no-explicit-any */
7270
const panel = this.getLovelacePanel() as any;
7371

7472
if (panel && panel.lovelace && panel.lovelace.config && panel.lovelace.config.config_template_card_vars) {
@@ -93,7 +91,7 @@ export class ConfigTemplateCard extends LitElement {
9391
if (oldHass) {
9492
for (const entity of this._config.entities) {
9593
const evaluatedTemplate = this._evaluateTemplate(entity);
96-
if (Boolean(this.hass && oldHass.states[evaluatedTemplate] !== this.hass.states[evaluatedTemplate])) {
94+
if (this.hass && oldHass.states[evaluatedTemplate] !== this.hass.states[evaluatedTemplate]) {
9795
return true;
9896
}
9997
}
@@ -152,9 +150,11 @@ export class ConfigTemplateCard extends LitElement {
152150
this.style.setProperty(prop, style[prop]);
153151
});
154152
}
155-
if (config.style) {
153+
if (config?.style) {
156154
Object.keys(config.style).forEach((prop) => {
157-
element.style.setProperty(prop, config.style[prop]);
155+
if (config.style) { // TypeScript requires a redundant check here, not sure why
156+
element.style.setProperty(prop, config.style[prop]);
157+
}
158158
});
159159
}
160160
}
@@ -170,11 +170,9 @@ export class ConfigTemplateCard extends LitElement {
170170
}
171171

172172
private async loadCardHelpers(): Promise<void> {
173-
/* eslint-disable @typescript-eslint/no-explicit-any */
174173
this._helpers = await (window as any).loadCardHelpers();
175174
}
176175

177-
/* eslint-disable @typescript-eslint/no-explicit-any */
178176
private _evaluateConfig(config: any): any {
179177
Object.entries(config).forEach((entry) => {
180178
const key = entry[0];
@@ -194,7 +192,6 @@ export class ConfigTemplateCard extends LitElement {
194192
return config;
195193
}
196194

197-
/* eslint-disable @typescript-eslint/no-explicit-any */
198195
private _evaluateArray(array: any): any {
199196
for (let i = 0; i < array.length; ++i) {
200197
const value = array[i];

src/types.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { LovelaceCardConfig, EntitiesCardEntityConfig, LovelaceElementConfigBase } from 'custom-card-helpers';
22

3+
interface StyleMixin {
4+
style?: Record<string, string>;
5+
}
6+
37
export interface ConfigTemplateConfig {
48
type: string;
59
entities: string[];
6-
variables?: string[] | { [key: string]: string };
7-
card?: LovelaceCardConfig;
8-
row?: EntitiesCardEntityConfig;
9-
element?: LovelaceElementConfigBase;
10+
variables?: Record<string, any> | any[];
11+
card?: LovelaceCardConfig & StyleMixin;
12+
row?: EntitiesCardEntityConfig & StyleMixin;
13+
element?: LovelaceElementConfigBase & StyleMixin;
1014
style?: Record<string, string>;
1115
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dom.iterable"
1010
],
1111
"noEmit": true,
12+
"sourceMap": true,
1213
"noUnusedParameters": true,
1314
"noImplicitReturns": true,
1415
"noFallthroughCasesInSwitch": true,
@@ -18,4 +19,4 @@
1819
"resolveJsonModule": true,
1920
"experimentalDecorators": true
2021
}
21-
}
22+
}

0 commit comments

Comments
 (0)