diff --git a/.eslintrc.json b/.eslintrc.json index 85636e335a..d126638239 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -35,55 +35,51 @@ "es6": true }, "rules": { - "class-methods-use-this": 0, - "new-cap": 0, - "prefer-template": 0, - "object-shorthand": 0, - "func-names": 0, - "prefer-arrow-callback": 0, - "no-underscore-dangle": 0, - "strict": 0, - "prefer-spread": 0, - "no-plusplus": 0, - "no-bitwise": 2, - "comma-dangle": 0, - "vars-on-top": 0, - "no-continue": 0, - "no-param-reassign": 0, - "no-multi-assign": 0, - "no-console": 2, - "radix": 0, - "no-alert": 0, - "no-return-await": 0, - "no-nested-ternary": 0, - "prefer-destructuring": 0, + "class-methods-use-this": "off", + "new-cap": "off", + "prefer-template": "off", + "object-shorthand": "off", + "func-names": "off", + "no-underscore-dangle": "off", + "strict": "off", + "no-plusplus": "off", + "no-bitwise": "error", + "comma-dangle": "off", + "vars-on-top": "off", + "no-continue": "off", + "no-param-reassign": "off", + "no-multi-assign": "off", + "no-console": "error", + "radix": "off", + "no-alert": "off", + "no-nested-ternary": "off", + "prefer-destructuring": "off", "no-restricted-globals": [2, "event"], - "prefer-promise-reject-errors": 0, - "import/order": 0, - "import/prefer-default-export": 0, - "import/no-unresolved": 0, - "import/no-cycle": 0, + "prefer-promise-reject-errors": "off", + "import/prefer-default-export": "off", + "import/no-default-export": "off", + "import/no-unresolved": "off", + "import/no-cycle": "off", "import/extensions": [ - 2, + "error", "ignorePackages", { "ts": "never", "js": "never" } ], "no-restricted-syntax": ["error", "LabeledStatement", "WithStatement"], - "object-curly-newline": 0, - "default-case": 0, - "wc/no-self-class": 0, - "no-shadow": 0, - "@typescript-eslint/camelcase": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-use-before-define": 0, - "@typescript-eslint/no-non-null-assertion": 0, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/no-unused-vars": 0, - "@typescript-eslint/explicit-function-return-type": 0, - "@typescript-eslint/explicit-module-boundary-types": 0, + "object-curly-newline": "off", + "default-case": "off", + "wc/no-self-class": "off", + "no-shadow": "off", + "@typescript-eslint/camelcase": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-shadow": ["error"], "@typescript-eslint/naming-convention": [ - 0, + "off", { "selector": "default", "format": ["camelCase", "snake_case"], @@ -101,9 +97,21 @@ "format": ["PascalCase"] } ], - "lit/attribute-value-entities": 0 + "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-vars": [ + "error", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_", + "ignoreRestSiblings": true + } + ], + "unused-imports/no-unused-imports": "error", + "lit/attribute-value-entities": "off" }, - "plugins": ["disable", "import", "lit", "prettier", "@typescript-eslint"], + "plugins": ["disable", "unused-imports"], "processor": "disable/disable", "ignorePatterns": ["src/resources/lit-virtualizer/*"] } diff --git a/cast/src/receiver/demo/cast-demo-lovelace.ts b/cast/src/receiver/demo/cast-demo-lovelace.ts index e948564485..1b0d85f0e5 100644 --- a/cast/src/receiver/demo/cast-demo-lovelace.ts +++ b/cast/src/receiver/demo/cast-demo-lovelace.ts @@ -5,8 +5,8 @@ import { import { castContext } from "../cast_context"; export const castDemoLovelace: () => LovelaceConfig = () => { - const touchSupported = castContext.getDeviceCapabilities() - .touch_input_supported; + const touchSupported = + castContext.getDeviceCapabilities().touch_input_supported; return { views: [ { diff --git a/demo/src/configs/arsaboo/lovelace.ts b/demo/src/configs/arsaboo/lovelace.ts index f1395dd588..5d3107dfdd 100644 --- a/demo/src/configs/arsaboo/lovelace.ts +++ b/demo/src/configs/arsaboo/lovelace.ts @@ -113,8 +113,7 @@ export const demoLovelaceArsaboo: DemoConfig["lovelace"] = (localize) => ({ on: "/assets/arsaboo/icons/light_bulb_on.png", }, state_filter: { - on: - "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", + on: "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", off: "brightness(80%) saturate(0.8)", }, style: { @@ -196,8 +195,7 @@ export const demoLovelaceArsaboo: DemoConfig["lovelace"] = (localize) => ({ on: "/assets/arsaboo/icons/light_bulb_on.png", }, state_filter: { - on: - "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", + on: "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", off: "brightness(80%) saturate(0.8)", }, style: { @@ -277,8 +275,7 @@ export const demoLovelaceArsaboo: DemoConfig["lovelace"] = (localize) => ({ on: "/assets/arsaboo/icons/light_bulb_on.png", }, state_filter: { - on: - "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", + on: "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", off: "brightness(80%) saturate(0.8)", }, style: { @@ -315,8 +312,7 @@ export const demoLovelaceArsaboo: DemoConfig["lovelace"] = (localize) => ({ on: "/assets/arsaboo/icons/light_bulb_on.png", }, state_filter: { - on: - "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", + on: "brightness(130%) saturate(1.5) drop-shadow(0px 0px 10px gold)", off: "brightness(80%) saturate(0.8)", }, style: { diff --git a/demo/src/configs/demo-configs.ts b/demo/src/configs/demo-configs.ts index 1c9897c9ad..28176aafa3 100644 --- a/demo/src/configs/demo-configs.ts +++ b/demo/src/configs/demo-configs.ts @@ -12,9 +12,8 @@ export const demoConfigs: Array<() => Promise> = [ // eslint-disable-next-line import/no-mutable-exports export let selectedDemoConfigIndex = 0; // eslint-disable-next-line import/no-mutable-exports -export let selectedDemoConfig: Promise = demoConfigs[ - selectedDemoConfigIndex -](); +export let selectedDemoConfig: Promise = + demoConfigs[selectedDemoConfigIndex](); export const setDemoConfig = async ( hass: MockHomeAssistant, diff --git a/demo/src/configs/teachingbirds/entities.ts b/demo/src/configs/teachingbirds/entities.ts index 476eab9219..ca2d945ffa 100644 --- a/demo/src/configs/teachingbirds/entities.ts +++ b/demo/src/configs/teachingbirds/entities.ts @@ -980,8 +980,7 @@ export const demoEntitiesTeachingbirds: DemoConfig["entities"] = () => icon: "mdi:account-off", custom_ui_state_card: "state-card-custom-ui", templates: { - icon: - "if (state === 'on') return 'mdi:account'; else if (state === 'off') return 'mdi:account-off';\n", + icon: "if (state === 'on') return 'mdi:account'; else if (state === 'off') return 'mdi:account-off';\n", icon_color: "if (state === 'on') return 'rgb(56, 150, 56)'; else if (state === 'off') return 'rgb(249, 251, 255)';\n", }, @@ -1005,8 +1004,7 @@ export const demoEntitiesTeachingbirds: DemoConfig["entities"] = () => icon: "mdi:account-multiple-minus", custom_ui_state_card: "state-card-custom-ui", templates: { - icon: - "if (state === 'on') return 'mdi:account-group'; else if (state === 'off') return 'mdi:account-multiple-minus';\n", + icon: "if (state === 'on') return 'mdi:account-group'; else if (state === 'off') return 'mdi:account-multiple-minus';\n", icon_color: "if (state === 'on') return 'rgb(56, 150, 56)'; else if (state === 'off') return 'rgb(249, 251, 255)';\n", }, diff --git a/demo/src/custom-cards/ha-demo-card.ts b/demo/src/custom-cards/ha-demo-card.ts index fcd48a90ab..72fedc0daf 100644 --- a/demo/src/custom-cards/ha-demo-card.ts +++ b/demo/src/custom-cards/ha-demo-card.ts @@ -19,7 +19,7 @@ export class HADemoCard extends LitElement implements LovelaceCard { @property({ attribute: false }) public hass!: MockHomeAssistant; - @state() private _switching?: boolean; + @state() private _switching = false; private _hidden = localStorage.hide_demo_card; @@ -27,12 +27,7 @@ export class HADemoCard extends LitElement implements LovelaceCard { return this._hidden ? 0 : 2; } - public setConfig( - // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-unused-vars - config: LovelaceCardConfig - // eslint-disable-next-line @typescript-eslint/no-empty-function - ) {} + public setConfig(_config: LovelaceCardConfig) {} protected render(): TemplateResult { if (this._hidden) { diff --git a/demo/src/stubs/history.ts b/demo/src/stubs/history.ts index 96fd787037..5b96b77ddf 100644 --- a/demo/src/stubs/history.ts +++ b/demo/src/stubs/history.ts @@ -67,14 +67,7 @@ const incrementalUnits = ["clients", "queries", "ads"]; export const mockHistory = (mockHass: MockHomeAssistant) => { mockHass.mockAPI( new RegExp("history/period/.+"), - ( - hass, - // @ts-ignore - method, - path, - // @ts-ignore - parameters - ) => { + (hass, _method, path, _parameters) => { const params = parseQuery(path.split("?")[1]); const entities = params.filter_entity_id.split(","); @@ -95,7 +88,7 @@ export const mockHistory = (mockHass: MockHomeAssistant) => { const numberState = Number(state.state); if (isNaN(numberState)) { - // eslint-disable-next-line + // eslint-disable-next-line no-console console.log( "Ignoring state with unparsable state but with a unit", entityId, diff --git a/demo/src/stubs/lovelace.ts b/demo/src/stubs/lovelace.ts index 74a38bc428..11dc854159 100644 --- a/demo/src/stubs/lovelace.ts +++ b/demo/src/stubs/lovelace.ts @@ -10,10 +10,9 @@ export const mockLovelace = ( localizePromise: Promise ) => { hass.mockWS("lovelace/config", () => - Promise.all([ - selectedDemoConfig, - localizePromise, - ]).then(([config, localize]) => config.lovelace(localize)) + Promise.all([selectedDemoConfig, localizePromise]).then( + ([config, localize]) => config.lovelace(localize) + ) ); hass.mockWS("lovelace/config/save", () => Promise.resolve()); diff --git a/gallery/src/demos/demo-automation-trace.ts b/gallery/src/demos/demo-automation-trace.ts index 7b96d81c00..a1faa152ac 100644 --- a/gallery/src/demos/demo-automation-trace.ts +++ b/gallery/src/demos/demo-automation-trace.ts @@ -2,12 +2,12 @@ import { html, css, LitElement, TemplateResult } from "lit"; import "../../../src/components/ha-card"; import "../../../src/components/trace/hat-script-graph"; import "../../../src/components/trace/hat-trace-timeline"; +import { customElement, property, state } from "lit/decorators"; import { provideHass } from "../../../src/fake_data/provide_hass"; import { HomeAssistant } from "../../../src/types"; import { DemoTrace } from "../data/traces/types"; import { basicTrace } from "../data/traces/basic_trace"; import { motionLightTrace } from "../data/traces/motion-light-trace"; -import { customElement, property, state } from "lit/decorators"; const traces: DemoTrace[] = [basicTrace, motionLightTrace]; diff --git a/gallery/src/demos/demo-integration-card.ts b/gallery/src/demos/demo-integration-card.ts index 4f5162c176..0b08a0aa3e 100644 --- a/gallery/src/demos/demo-integration-card.ts +++ b/gallery/src/demos/demo-integration-card.ts @@ -2,6 +2,8 @@ import { html, css, LitElement, TemplateResult } from "lit"; import "../../../src/components/ha-formfield"; import "../../../src/components/ha-switch"; +import { classMap } from "lit/directives/class-map"; +import { customElement, property, state } from "lit/decorators"; import { IntegrationManifest } from "../../../src/data/integration"; import { provideHass } from "../../../src/fake_data/provide_hass"; @@ -15,8 +17,6 @@ import type { } from "../../../src/panels/config/integrations/ha-config-integrations"; import { DeviceRegistryEntry } from "../../../src/data/device_registry"; import { EntityRegistryEntry } from "../../../src/data/entity_registry"; -import { classMap } from "lit/directives/class-map"; -import { customElement, property, state } from "lit/decorators"; const createConfigEntry = ( title: string, diff --git a/hassio/src/addon-view/documentation/hassio-addon-documentation-tab.ts b/hassio/src/addon-view/documentation/hassio-addon-documentation-tab.ts index 179598f099..ba12198a97 100644 --- a/hassio/src/addon-view/documentation/hassio-addon-documentation-tab.ts +++ b/hassio/src/addon-view/documentation/hassio-addon-documentation-tab.ts @@ -2,6 +2,7 @@ import "../../../../src/components/ha-card"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import "../../../../src/components/ha-circular-progress"; import "../../../../src/components/ha-markdown"; +import { customElement, property, state } from "lit/decorators"; import { fetchHassioAddonDocumentation, HassioAddonDetails, @@ -12,7 +13,6 @@ import { haStyle } from "../../../../src/resources/styles"; import { HomeAssistant } from "../../../../src/types"; import { hassioStyle } from "../../resources/hassio-style"; import { Supervisor } from "../../../../src/data/supervisor/supervisor"; -import { customElement, property, state } from "lit/decorators"; @customElement("hassio-addon-documentation-tab") class HassioAddonDocumentationDashboard extends LitElement { diff --git a/hassio/src/dialogs/network/dialog-hassio-network.ts b/hassio/src/dialogs/network/dialog-hassio-network.ts index 36adbabf45..4b0fd9c9dc 100644 --- a/hassio/src/dialogs/network/dialog-hassio-network.ts +++ b/hassio/src/dialogs/network/dialog-hassio-network.ts @@ -41,7 +41,8 @@ const IP_VERSIONS = ["ipv4", "ipv6"]; @customElement("dialog-hassio-network") export class DialogHassioNetwork extends LitElement - implements HassDialog { + implements HassDialog +{ @property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public supervisor!: Supervisor; @@ -492,7 +493,7 @@ export class DialogHassioNetwork } private _handleRadioValueChangedAp(ev: CustomEvent): void { - const value = ((ev.target as any).value as string) as + const value = (ev.target as any).value as string as | "open" | "wep" | "wpa-psk"; diff --git a/hassio/src/dialogs/registries/dialog-hassio-registries.ts b/hassio/src/dialogs/registries/dialog-hassio-registries.ts index 043ca71de5..5f39f8155b 100644 --- a/hassio/src/dialogs/registries/dialog-hassio-registries.ts +++ b/hassio/src/dialogs/registries/dialog-hassio-registries.ts @@ -161,9 +161,9 @@ class HassioRegistriesDialog extends LitElement { public focus(): void { this.updateComplete.then(() => - (this.shadowRoot?.querySelector( - "[dialogInitialFocus]" - ) as HTMLElement)?.focus() + ( + this.shadowRoot?.querySelector("[dialogInitialFocus]") as HTMLElement + )?.focus() ); } diff --git a/hassio/src/dialogs/repositories/dialog-hassio-repositories.ts b/hassio/src/dialogs/repositories/dialog-hassio-repositories.ts index 8130e0d781..7ff50b7e98 100644 --- a/hassio/src/dialogs/repositories/dialog-hassio-repositories.ts +++ b/hassio/src/dialogs/repositories/dialog-hassio-repositories.ts @@ -161,9 +161,9 @@ class HassioRepositoriesDialog extends LitElement { public focus() { this.updateComplete.then(() => - (this.shadowRoot?.querySelector( - "[dialogInitialFocus]" - ) as HTMLElement)?.focus() + ( + this.shadowRoot?.querySelector("[dialogInitialFocus]") as HTMLElement + )?.focus() ); } diff --git a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot-upload.ts b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot-upload.ts index d2ffb1f035..1c23944951 100644 --- a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot-upload.ts +++ b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot-upload.ts @@ -12,7 +12,8 @@ import { HassioSnapshotUploadDialogParams } from "./show-dialog-snapshot-upload" @customElement("dialog-hassio-snapshot-upload") export class DialogHassioSnapshotUpload extends LitElement - implements HassDialog { + implements HassDialog +{ @property({ attribute: false }) public hass!: HomeAssistant; @state() private _params?: HassioSnapshotUploadDialogParams; diff --git a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts index 93938903c9..5228488fb0 100755 --- a/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts +++ b/hassio/src/dialogs/snapshot/dialog-hassio-snapshot.ts @@ -30,7 +30,8 @@ import { HassioSnapshotDialogParams } from "./show-dialog-hassio-snapshot"; @customElement("dialog-hassio-snapshot") class HassioSnapshotDialog extends LitElement - implements HassDialog { + implements HassDialog +{ @property({ attribute: false }) public hass!: HomeAssistant; @state() private _error?: string; @@ -297,8 +298,7 @@ class HassioSnapshotDialog if (window.location.href.includes("ui.nabu.casa")) { const confirm = await showConfirmationDialog(this, { title: "Potential slow download", - text: - "Downloading snapshots over the Nabu Casa URL will take some time, it is recomended to use your local URL instead, do you want to continue?", + text: "Downloading snapshots over the Nabu Casa URL will take some time, it is recomended to use your local URL instead, do you want to continue?", confirmText: "continue", dismissText: "cancel", }); diff --git a/hassio/src/dialogs/update/dialog-supervisor-update.ts b/hassio/src/dialogs/update/dialog-supervisor-update.ts index 4e27303681..f6757c1481 100644 --- a/hassio/src/dialogs/update/dialog-supervisor-update.ts +++ b/hassio/src/dialogs/update/dialog-supervisor-update.ts @@ -49,9 +49,9 @@ class DialogSupervisorUpdate extends LitElement { public focus(): void { this.updateComplete.then(() => - (this.shadowRoot?.querySelector( - "[dialogInitialFocus]" - ) as HTMLElement)?.focus() + ( + this.shadowRoot?.querySelector("[dialogInitialFocus]") as HTMLElement + )?.focus() ); } diff --git a/hassio/src/hassio-main.ts b/hassio/src/hassio-main.ts index e4a777c664..93181aa106 100644 --- a/hassio/src/hassio-main.ts +++ b/hassio/src/hassio-main.ts @@ -121,7 +121,7 @@ export class HassioMain extends SupervisorBaseElement { } } else { themeName = - ((this.hass.selectedTheme as unknown) as string) || + (this.hass.selectedTheme as unknown as string) || this.hass.themes.default_theme; } diff --git a/hassio/src/hassio-my-redirect.ts b/hassio/src/hassio-my-redirect.ts index 54d0d928ca..cd38d85d57 100644 --- a/hassio/src/hassio-my-redirect.ts +++ b/hassio/src/hassio-my-redirect.ts @@ -1,19 +1,19 @@ -import { html, LitElement, TemplateResult } from "lit"; import { sanitizeUrl } from "@braintree/sanitize-url"; +import { html, LitElement, TemplateResult } from "lit"; +import { customElement, property, state } from "lit/decorators"; +import { navigate } from "../../src/common/navigate"; import { createSearchParam, extractSearchParamsObject, } from "../../src/common/url/search-params"; +import { Supervisor } from "../../src/data/supervisor/supervisor"; import "../../src/layouts/hass-error-screen"; import { ParamType, Redirect, Redirects, } from "../../src/panels/my/ha-panel-my"; -import { navigate } from "../../src/common/navigate"; import { HomeAssistant, Route } from "../../src/types"; -import { Supervisor } from "../../src/data/supervisor/supervisor"; -import { customElement, property, state } from "lit/decorators"; const REDIRECTS: Redirects = { supervisor: { diff --git a/hassio/src/supervisor-base-element.ts b/hassio/src/supervisor-base-element.ts index 9811f36266..7bd0fbb8ca 100644 --- a/hassio/src/supervisor-base-element.ts +++ b/hassio/src/supervisor-base-element.ts @@ -86,10 +86,8 @@ export class SupervisorBaseElement extends urlSyncMixin( const unsubs = Object.keys(this._unsubs); for (const collection of Object.keys(this._collections)) { if (!unsubs.includes(collection)) { - this._unsubs[collection] = this._collections[ - collection - ].subscribe((data) => - this._updateSupervisor({ [collection]: data }) + this._unsubs[collection] = this._collections[collection].subscribe( + (data) => this._updateSupervisor({ [collection]: data }) ); } } diff --git a/package.json b/package.json index fb870a319c..b0324d7a61 100644 --- a/package.json +++ b/package.json @@ -172,21 +172,22 @@ "@types/mocha": "^8.2.2", "@types/sortablejs": "^1.10.6", "@types/webspeechapi": "^0.0.29", - "@typescript-eslint/eslint-plugin": "^4.22.0", - "@typescript-eslint/parser": "^4.22.0", + "@typescript-eslint/eslint-plugin": "^4.28.3", + "@typescript-eslint/parser": "^4.28.3", "@web/dev-server": "^0.0.24", "@web/dev-server-rollup": "^0.2.11", "babel-loader": "^8.2.2", "chai": "^4.3.4", "del": "^4.0.0", - "eslint": "^7.25.0", + "eslint": "^7.30.0", "eslint-config-airbnb-typescript": "^12.3.1", "eslint-config-prettier": "^8.3.0", "eslint-import-resolver-webpack": "^0.13.1", "eslint-plugin-disable": "^2.0.1", - "eslint-plugin-import": "^2.22.1", - "eslint-plugin-lit": "^1.3.0", + "eslint-plugin-import": "^2.23.4", + "eslint-plugin-lit": "^1.5.1", "eslint-plugin-prettier": "^3.4.0", + "eslint-plugin-unused-imports": "^1.1.2", "eslint-plugin-wc": "^1.3.0", "fancy-log": "^1.3.3", "fs-extra": "^7.0.1", @@ -198,7 +199,7 @@ "gulp-zopfli-green": "^3.0.1", "html-minifier": "^4.0.0", "husky": "^1.3.1", - "lint-staged": "^10.5.4", + "lint-staged": "^11.0.1", "lit-analyzer": "^1.2.1", "lodash.template": "^4.5.0", "magic-string": "^0.25.7", @@ -207,7 +208,7 @@ "mocha": "^8.4.0", "object-hash": "^2.0.3", "open": "^7.0.4", - "prettier": "^2.0.4", + "prettier": "^2.3.2", "require-dir": "^1.2.0", "rollup": "^2.8.2", "rollup-plugin-string": "^3.0.0", @@ -220,7 +221,7 @@ "terser-webpack-plugin": "^5.1.4", "ts-lit-plugin": "^1.2.1", "ts-mocha": "^8.0.0", - "typescript": "^4.2.4", + "typescript": "^4.3.5", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0", "webpack": "^5.43.0", diff --git a/src/common/datetime/check_options_support.ts b/src/common/datetime/check_options_support.ts index 614f7f9828..3057a8cae3 100644 --- a/src/common/datetime/check_options_support.ts +++ b/src/common/datetime/check_options_support.ts @@ -26,6 +26,9 @@ function checkToLocaleStringSupportsOptions() { return false; } -export const toLocaleDateStringSupportsOptions = checkToLocaleDateStringSupportsOptions(); -export const toLocaleTimeStringSupportsOptions = checkToLocaleTimeStringSupportsOptions(); -export const toLocaleStringSupportsOptions = checkToLocaleStringSupportsOptions(); +export const toLocaleDateStringSupportsOptions = + checkToLocaleDateStringSupportsOptions(); +export const toLocaleTimeStringSupportsOptions = + checkToLocaleTimeStringSupportsOptions(); +export const toLocaleStringSupportsOptions = + checkToLocaleStringSupportsOptions(); diff --git a/src/common/decorators/local-storage.ts b/src/common/decorators/local-storage.ts index 8456c5be48..960afa65b0 100644 --- a/src/common/decorators/local-storage.ts +++ b/src/common/decorators/local-storage.ts @@ -82,67 +82,71 @@ class Storage { const storage = new Storage(); -export const LocalStorage = ( - storageKey?: string, - property?: boolean, - propertyOptions?: PropertyDeclaration -): any => (clsElement: ClassElement) => { - const key = String(clsElement.key); - storageKey = storageKey || String(clsElement.key); - const initVal = clsElement.initializer ? clsElement.initializer() : undefined; +export const LocalStorage = + ( + storageKey?: string, + property?: boolean, + propertyOptions?: PropertyDeclaration + ): any => + (clsElement: ClassElement) => { + const key = String(clsElement.key); + storageKey = storageKey || String(clsElement.key); + const initVal = clsElement.initializer + ? clsElement.initializer() + : undefined; - storage.addFromStorage(storageKey); + storage.addFromStorage(storageKey); - const subscribe = (el: ReactiveElement): UnsubscribeFunc => - storage.subscribeChanges(storageKey!, (oldValue) => { - el.requestUpdate(clsElement.key, oldValue); - }); + const subscribe = (el: ReactiveElement): UnsubscribeFunc => + storage.subscribeChanges(storageKey!, (oldValue) => { + el.requestUpdate(clsElement.key, oldValue); + }); - const getValue = (): any => - storage.hasKey(storageKey!) ? storage.getValue(storageKey!) : initVal; + const getValue = (): any => + storage.hasKey(storageKey!) ? storage.getValue(storageKey!) : initVal; - const setValue = (el: ReactiveElement, value: any) => { - let oldValue: unknown | undefined; - if (property) { - oldValue = getValue(); - } - storage.setValue(storageKey!, value); - if (property) { - el.requestUpdate(clsElement.key, oldValue); - } - }; - - return { - kind: "method", - placement: "prototype", - key: clsElement.key, - descriptor: { - set(this: ReactiveElement, value: unknown) { - setValue(this, value); - }, - get() { - return getValue(); - }, - enumerable: true, - configurable: true, - }, - finisher(cls: typeof ReactiveElement) { + const setValue = (el: ReactiveElement, value: any) => { + let oldValue: unknown | undefined; if (property) { - const connectedCallback = cls.prototype.connectedCallback; - const disconnectedCallback = cls.prototype.disconnectedCallback; - cls.prototype.connectedCallback = function () { - connectedCallback.call(this); - this[`__unbsubLocalStorage${key}`] = subscribe(this); - }; - cls.prototype.disconnectedCallback = function () { - disconnectedCallback.call(this); - this[`__unbsubLocalStorage${key}`](); - }; - cls.createProperty(clsElement.key, { - noAccessor: true, - ...propertyOptions, - }); + oldValue = getValue(); } - }, + storage.setValue(storageKey!, value); + if (property) { + el.requestUpdate(clsElement.key, oldValue); + } + }; + + return { + kind: "method", + placement: "prototype", + key: clsElement.key, + descriptor: { + set(this: ReactiveElement, value: unknown) { + setValue(this, value); + }, + get() { + return getValue(); + }, + enumerable: true, + configurable: true, + }, + finisher(cls: typeof ReactiveElement) { + if (property) { + const connectedCallback = cls.prototype.connectedCallback; + const disconnectedCallback = cls.prototype.disconnectedCallback; + cls.prototype.connectedCallback = function () { + connectedCallback.call(this); + this[`__unbsubLocalStorage${key}`] = subscribe(this); + }; + cls.prototype.disconnectedCallback = function () { + disconnectedCallback.call(this); + this[`__unbsubLocalStorage${key}`](); + }; + cls.createProperty(clsElement.key, { + noAccessor: true, + ...propertyOptions, + }); + } + }, + }; }; -}; diff --git a/src/common/decorators/restore-scroll.ts b/src/common/decorators/restore-scroll.ts index e7353e729f..9668fc47d3 100644 --- a/src/common/decorators/restore-scroll.ts +++ b/src/common/decorators/restore-scroll.ts @@ -1,33 +1,33 @@ import type { LitElement } from "lit"; import type { ClassElement } from "../../types"; -export const restoreScroll = (selector: string): any => ( - element: ClassElement -) => ({ - kind: "method", - placement: "prototype", - key: element.key, - descriptor: { - set(this: LitElement, value: number) { - this[`__${String(element.key)}`] = value; +export const restoreScroll = + (selector: string): any => + (element: ClassElement) => ({ + kind: "method", + placement: "prototype", + key: element.key, + descriptor: { + set(this: LitElement, value: number) { + this[`__${String(element.key)}`] = value; + }, + get(this: LitElement) { + return this[`__${String(element.key)}`]; + }, + enumerable: true, + configurable: true, }, - get(this: LitElement) { - return this[`__${String(element.key)}`]; - }, - enumerable: true, - configurable: true, - }, - finisher(cls: typeof LitElement) { - const connectedCallback = cls.prototype.connectedCallback; - cls.prototype.connectedCallback = function () { - connectedCallback.call(this); - if (this[element.key]) { - const target = this.renderRoot.querySelector(selector); - if (!target) { - return; + finisher(cls: typeof LitElement) { + const connectedCallback = cls.prototype.connectedCallback; + cls.prototype.connectedCallback = function () { + connectedCallback.call(this); + if (this[element.key]) { + const target = this.renderRoot.querySelector(selector); + if (!target) { + return; + } + target.scrollTop = this[element.key]; } - target.scrollTop = this[element.key]; - } - }; - }, -}); + }; + }, + }); diff --git a/src/common/search/search-input.ts b/src/common/search/search-input.ts index 5a45277a0e..b7405a41cf 100644 --- a/src/common/search/search-input.ts +++ b/src/common/search/search-input.ts @@ -67,9 +67,11 @@ class SearchInput extends LitElement { changedProps.has("noUnderline") && (this.noUnderline || changedProps.get("noUnderline") !== undefined) ) { - (this._input.inputElement!.parentElement!.shadowRoot!.querySelector( - "div.unfocused-line" - ) as HTMLElement).style.display = this.noUnderline ? "none" : "block"; + ( + this._input.inputElement!.parentElement!.shadowRoot!.querySelector( + "div.unfocused-line" + ) as HTMLElement + ).style.display = this.noUnderline ? "none" : "block"; } } diff --git a/src/common/string/is_timestamp.ts b/src/common/string/is_timestamp.ts index e4b7649529..f36f4a7933 100644 --- a/src/common/string/is_timestamp.ts +++ b/src/common/string/is_timestamp.ts @@ -6,6 +6,7 @@ // 3. Disallow dates based on week number. // 4. Disallow dates only consisting of a year. // https://regex101.com/r/kc5C14/3 -const regexp = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])[T| ](((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)(\8[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)$/; +const regexp = + /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])[T| ](((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)(\8[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)$/; export const isTimestamp = (input: string): boolean => regexp.test(input); diff --git a/src/components/buttons/ha-call-service-button.js b/src/components/buttons/ha-call-service-button.js index 391c9b8e22..6695ea7b0d 100644 --- a/src/components/buttons/ha-call-service-button.js +++ b/src/components/buttons/ha-call-service-button.js @@ -64,18 +64,18 @@ class HaCallServiceButton extends EventsMixin(PolymerElement) { this.hass .callService(this.domain, this.service, this.serviceData) .then( - function () { + () => { el.progress = false; el.$.progress.actionSuccess(); eventData.success = true; }, - function () { + () => { el.progress = false; el.$.progress.actionError(); eventData.success = false; } ) - .then(function () { + .then(() => { el.fire("hass-service-called", eventData); }); } diff --git a/src/components/chart/state-history-chart-timeline.ts b/src/components/chart/state-history-chart-timeline.ts index fe6873ed0b..d2af0deb9f 100644 --- a/src/components/chart/state-history-chart-timeline.ts +++ b/src/components/chart/state-history-chart-timeline.ts @@ -176,9 +176,9 @@ export class StateHistoryChartTimeline extends LitElement { labelColor: (item) => ({ borderColor: (item.dataset.data[item.dataIndex] as TimeLineData) .color!, - backgroundColor: (item.dataset.data[ - item.dataIndex - ] as TimeLineData).color!, + backgroundColor: ( + item.dataset.data[item.dataIndex] as TimeLineData + ).color!, }), }, }, diff --git a/src/components/chart/timeline-chart/textbar-element.ts b/src/components/chart/timeline-chart/textbar-element.ts index 1348021b0e..93cc953ccd 100644 --- a/src/components/chart/timeline-chart/textbar-element.ts +++ b/src/components/chart/timeline-chart/textbar-element.ts @@ -19,10 +19,9 @@ export class TextBarElement extends BarElement { draw(ctx) { super.draw(ctx); const options = this.options as TextBaroptions; - const { x, y, base, width, text } = (this as BarElement< - TextBarProps, - TextBaroptions - >).getProps(["x", "y", "base", "width", "text"]); + const { x, y, base, width, text } = ( + this as BarElement + ).getProps(["x", "y", "base", "width", "text"]); if (!text) { return; diff --git a/src/components/data-table/ha-data-table.ts b/src/components/data-table/ha-data-table.ts index c7c2927c33..30eda28492 100644 --- a/src/components/data-table/ha-data-table.ts +++ b/src/components/data-table/ha-data-table.ts @@ -1,4 +1,3 @@ -import { Layout1d, scroll } from "../../resources/lit-virtualizer"; import deepClone from "deep-clone-simple"; import { css, @@ -19,6 +18,7 @@ import { classMap } from "lit/directives/class-map"; import { ifDefined } from "lit/directives/if-defined"; import { styleMap } from "lit/directives/style-map"; import memoizeOne from "memoize-one"; +import { Layout1d, scroll } from "../../resources/lit-virtualizer"; import { restoreScroll } from "../../common/decorators/restore-scroll"; import { fireEvent } from "../../common/dom/fire_event"; import "../../common/search/search-input"; @@ -360,9 +360,8 @@ export class HaDataTable extends LitElement { .rowId=${row[this.id]} @click=${this._handleRowClick} class="mdc-data-table__row ${classMap({ - "mdc-data-table__row--selected": this._checkedRows.includes( - String(row[this.id]) - ), + "mdc-data-table__row--selected": + this._checkedRows.includes(String(row[this.id])), clickable: this.clickable, })}" aria-selected=${ifDefined( @@ -406,17 +405,15 @@ export class HaDataTable extends LitElement { "mdc-data-table__cell--icon": Boolean( column.type === "icon" ), - "mdc-data-table__cell--icon-button": Boolean( - column.type === "icon-button" - ), + "mdc-data-table__cell--icon-button": + Boolean(column.type === "icon-button"), grows: Boolean(column.grows), forceLTR: Boolean(column.forceLTR), })}" style=${column.width ? styleMap({ - [column.grows - ? "minWidth" - : "width"]: column.width, + [column.grows ? "minWidth" : "width"]: + column.width, maxWidth: column.maxWidth ? column.maxWidth : "", diff --git a/src/components/device/ha-area-devices-picker.ts b/src/components/device/ha-area-devices-picker.ts index 712e1b1bb3..f34fdd7451 100644 --- a/src/components/device/ha-area-devices-picker.ts +++ b/src/components/device/ha-area-devices-picker.ts @@ -15,6 +15,7 @@ import { PropertyValues, TemplateResult, } from "lit"; +import { ComboBoxLitRenderer, comboBoxRenderer } from "lit-vaadin-helpers"; import { customElement, property, state } from "lit/decorators"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../common/dom/fire_event"; @@ -38,7 +39,6 @@ import { PolymerChangedEvent } from "../../polymer-types"; import { HomeAssistant } from "../../types"; import "../ha-svg-icon"; import "./ha-devices-picker"; -import { ComboBoxLitRenderer, comboBoxRenderer } from "lit-vaadin-helpers"; interface DevicesByArea { [areaId: string]: AreaDevices; diff --git a/src/components/device/ha-device-picker.ts b/src/components/device/ha-device-picker.ts index 1333f9fb82..cea66c66c3 100644 --- a/src/components/device/ha-device-picker.ts +++ b/src/components/device/ha-device-picker.ts @@ -11,6 +11,7 @@ import { } from "lit"; import { customElement, property, state, query } from "lit/decorators"; import memoizeOne from "memoize-one"; +import { ComboBoxLitRenderer } from "lit-vaadin-helpers"; import { fireEvent } from "../../common/dom/fire_event"; import { computeDomain } from "../../common/entity/compute_domain"; import { compare } from "../../common/string/compare"; @@ -33,7 +34,6 @@ import { PolymerChangedEvent } from "../../polymer-types"; import { HomeAssistant } from "../../types"; import "../ha-combo-box"; import type { HaComboBox } from "../ha-combo-box"; -import { ComboBoxLitRenderer } from "lit-vaadin-helpers"; interface Device { name: string; diff --git a/src/components/ha-addon-picker.ts b/src/components/ha-addon-picker.ts index f868d5ead6..0ce5a96e8f 100644 --- a/src/components/ha-addon-picker.ts +++ b/src/components/ha-addon-picker.ts @@ -1,5 +1,6 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state, query } from "lit/decorators"; +import { ComboBoxLitRenderer } from "lit-vaadin-helpers"; import { isComponentLoaded } from "../common/config/is_component_loaded"; import { fireEvent } from "../common/dom/fire_event"; import { compare } from "../common/string/compare"; @@ -9,7 +10,6 @@ import { showAlertDialog } from "../dialogs/generic/show-dialog-box"; import { PolymerChangedEvent } from "../polymer-types"; import { HomeAssistant } from "../types"; import { HaComboBox } from "./ha-combo-box"; -import { ComboBoxLitRenderer } from "lit-vaadin-helpers"; const rowRenderer: ComboBoxLitRenderer = (item) => html`