From 1d13947e71cd5ce9b3d02616dd7b2e32d556238e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 25 Nov 2020 10:40:32 +0100 Subject: [PATCH] Use Record type (#7798) --- demo/src/configs/types.ts | 2 +- src/common/dom/apply_themes_on_element.ts | 4 ++-- src/common/dom/dynamic-element-directive.ts | 2 +- src/common/translations/localize.ts | 2 +- src/common/url/search-params.ts | 2 +- src/components/ha-form/ha-form.ts | 2 +- src/components/ha-icon.ts | 2 +- src/components/map/ha-locations-editor.ts | 2 +- src/data/config_flow.ts | 2 +- src/data/conversation.ts | 2 +- src/data/data_entry_flow.ts | 14 +++++++------- src/data/hassio/hardware.ts | 4 ++-- src/data/history.ts | 2 +- src/data/options_flow.ts | 2 +- src/data/script.ts | 6 +++--- .../config-flow/show-dialog-data-entry-flow.ts | 2 +- src/dialogs/config-flow/step-flow-form.ts | 2 +- src/external_app/external_messaging.ts | 2 +- src/fake_data/entity.ts | 6 +++--- src/fake_data/provide_hass.ts | 4 ++-- .../action/types/ha-automation-action-device_id.ts | 2 +- .../types/ha-automation-condition-device.ts | 2 +- .../trigger/types/ha-automation-trigger-device.ts | 2 +- .../lovelace/cards/hui-history-graph-card.ts | 2 +- src/panels/lovelace/cards/hui-map-card.ts | 2 +- src/panels/lovelace/entity-rows/types.ts | 4 ++-- src/types.ts | 10 +++++----- 27 files changed, 45 insertions(+), 45 deletions(-) diff --git a/demo/src/configs/types.ts b/demo/src/configs/types.ts index c0643d65ac..c8b096cd6e 100644 --- a/demo/src/configs/types.ts +++ b/demo/src/configs/types.ts @@ -9,5 +9,5 @@ export interface DemoConfig { authorUrl: string; lovelace: (localize: LocalizeFunc) => LovelaceConfig; entities: (localize: LocalizeFunc) => Entity[]; - theme: () => { [key: string]: string } | null; + theme: () => Record | null; } diff --git a/src/common/dom/apply_themes_on_element.ts b/src/common/dom/apply_themes_on_element.ts index 4e1aeb9ec6..1f83ba722f 100644 --- a/src/common/dom/apply_themes_on_element.ts +++ b/src/common/dom/apply_themes_on_element.ts @@ -13,10 +13,10 @@ import { rgbContrast } from "../color/rgb"; interface ProcessedTheme { keys: { [key: string]: "" }; - styles: { [key: string]: string }; + styles: Record; } -let PROCESSED_THEMES: { [key: string]: ProcessedTheme } = {}; +let PROCESSED_THEMES: Record = {}; /** * Apply a theme to an element by setting the CSS variables on it. diff --git a/src/common/dom/dynamic-element-directive.ts b/src/common/dom/dynamic-element-directive.ts index fe863e48b8..e3e48e57af 100644 --- a/src/common/dom/dynamic-element-directive.ts +++ b/src/common/dom/dynamic-element-directive.ts @@ -1,7 +1,7 @@ import { directive, NodePart, Part } from "lit-html"; export const dynamicElement = directive( - (tag: string, properties?: { [key: string]: any }) => (part: Part): void => { + (tag: string, properties?: Record) => (part: Part): void => { if (!(part instanceof NodePart)) { throw new Error( "dynamicElementDirective can only be used in content bindings" diff --git a/src/common/translations/localize.ts b/src/common/translations/localize.ts index 6ebba251b8..47bbca7692 100644 --- a/src/common/translations/localize.ts +++ b/src/common/translations/localize.ts @@ -102,7 +102,7 @@ export const computeLocalize = async ( export const localizeKey = ( localize: LocalizeFunc, key: string, - placeholders?: { [key: string]: string } + placeholders?: Record ) => { const args: [string, ...string[]] = [key]; if (placeholders) { diff --git a/src/common/url/search-params.ts b/src/common/url/search-params.ts index 5894823b69..9d67cdb472 100644 --- a/src/common/url/search-params.ts +++ b/src/common/url/search-params.ts @@ -1,4 +1,4 @@ -export const extractSearchParamsObject = (): { [key: string]: string } => { +export const extractSearchParamsObject = (): Record => { const query = {}; const searchParams = new URLSearchParams(location.search); for (const [key, value] of searchParams.entries()) { diff --git a/src/components/ha-form/ha-form.ts b/src/components/ha-form/ha-form.ts index afc69a15d6..87af775202 100644 --- a/src/components/ha-form/ha-form.ts +++ b/src/components/ha-form/ha-form.ts @@ -54,7 +54,7 @@ export interface HaFormSelectSchema extends HaFormBaseSchema { export interface HaFormMultiSelectSchema extends HaFormBaseSchema { type: "multi_select"; - options?: { [key: string]: string } | string[] | Array<[string, string]>; + options?: Record | string[] | Array<[string, string]>; } export interface HaFormFloatSchema extends HaFormBaseSchema { diff --git a/src/components/ha-icon.ts b/src/components/ha-icon.ts index b76adac8b4..8fe065bc6e 100644 --- a/src/components/ha-icon.ts +++ b/src/components/ha-icon.ts @@ -39,7 +39,7 @@ checkCacheVersion(); const debouncedWriteCache = debounce(() => writeCache(chunks), 2000); -const cachedIcons: { [key: string]: string } = {}; +const cachedIcons: Record = {}; @customElement("ha-icon") export class HaIcon extends LitElement { diff --git a/src/components/map/ha-locations-editor.ts b/src/components/map/ha-locations-editor.ts index a12021c11f..8b67b9ff2e 100644 --- a/src/components/map/ha-locations-editor.ts +++ b/src/components/map/ha-locations-editor.ts @@ -66,7 +66,7 @@ export class HaLocationsEditor extends LitElement { private _locationMarkers?: { [key: string]: Marker | Circle }; - private _circles: { [key: string]: Circle } = {}; + private _circles: Record = {}; public fitMap(): void { if ( diff --git a/src/data/config_flow.ts b/src/data/config_flow.ts index 367924e015..0752659abc 100644 --- a/src/data/config_flow.ts +++ b/src/data/config_flow.ts @@ -31,7 +31,7 @@ export const fetchConfigFlow = (hass: HomeAssistant, flowId: string) => export const handleConfigFlowStep = ( hass: HomeAssistant, flowId: string, - data: { [key: string]: any } + data: Record ) => hass.callApi( "POST", diff --git a/src/data/conversation.ts b/src/data/conversation.ts index 10b9abe7ab..84ed420ff5 100644 --- a/src/data/conversation.ts +++ b/src/data/conversation.ts @@ -1,7 +1,7 @@ import { HomeAssistant } from "../types"; interface ProcessResults { - card: { [key: string]: { [key: string]: string } }; + card: { [key: string]: Record }; speech: { [SpeechType in "plain" | "ssml"]: { extra_data: any; speech: string }; }; diff --git a/src/data/data_entry_flow.ts b/src/data/data_entry_flow.ts index a9a7afbf69..63210ebee5 100644 --- a/src/data/data_entry_flow.ts +++ b/src/data/data_entry_flow.ts @@ -14,7 +14,7 @@ export interface DataEntryFlowProgress { handler: string; step_id: string; context: { - title_placeholders: { [key: string]: string }; + title_placeholders: Record; [key: string]: any; }; } @@ -25,8 +25,8 @@ export interface DataEntryFlowStepForm { handler: string; step_id: string; data_schema: HaFormSchema[]; - errors: { [key: string]: string }; - description_placeholders: { [key: string]: string }; + errors: Record; + description_placeholders: Record; } export interface DataEntryFlowStepExternal { @@ -35,7 +35,7 @@ export interface DataEntryFlowStepExternal { handler: string; step_id: string; url: string; - description_placeholders: { [key: string]: string }; + description_placeholders: Record; } export interface DataEntryFlowStepCreateEntry { @@ -47,7 +47,7 @@ export interface DataEntryFlowStepCreateEntry { // Config entry ID result: string; description: string; - description_placeholders: { [key: string]: string }; + description_placeholders: Record; } export interface DataEntryFlowStepAbort { @@ -55,7 +55,7 @@ export interface DataEntryFlowStepAbort { flow_id: string; handler: string; reason: string; - description_placeholders: { [key: string]: string }; + description_placeholders: Record; } export interface DataEntryFlowStepProgress { @@ -64,7 +64,7 @@ export interface DataEntryFlowStepProgress { handler: string; step_id: string; progress_action: string; - description_placeholders: { [key: string]: string }; + description_placeholders: Record; } export type DataEntryFlowStep = diff --git a/src/data/hassio/hardware.ts b/src/data/hassio/hardware.ts index 863a16d70d..2df7a8bcdd 100644 --- a/src/data/hassio/hardware.ts +++ b/src/data/hassio/hardware.ts @@ -8,8 +8,8 @@ export interface HassioHardwareAudioDevice { interface HassioHardwareAudioList { audio: { - input: { [key: string]: string }; - output: { [key: string]: string }; + input: Record; + output: Record; }; } diff --git a/src/data/history.ts b/src/data/history.ts index 16bb07c782..7bab985c1c 100644 --- a/src/data/history.ts +++ b/src/data/history.ts @@ -19,7 +19,7 @@ const LINE_ATTRIBUTES_TO_KEEP = [ export interface LineChartState { state: string; last_changed: string; - attributes?: { [key: string]: any }; + attributes?: Record; } export interface LineChartEntity { diff --git a/src/data/options_flow.ts b/src/data/options_flow.ts index 2f789ce267..6b710d89a9 100644 --- a/src/data/options_flow.ts +++ b/src/data/options_flow.ts @@ -20,7 +20,7 @@ export const fetchOptionsFlow = (hass: HomeAssistant, flowId: string) => export const handleOptionsFlowStep = ( hass: HomeAssistant, flowId: string, - data: { [key: string]: any } + data: Record ) => hass.callApi( "POST", diff --git a/src/data/script.ts b/src/data/script.ts index 3becd56e0a..cb434d7dfc 100644 --- a/src/data/script.ts +++ b/src/data/script.ts @@ -29,14 +29,14 @@ export interface ScriptConfig { export interface EventAction { event: string; - event_data?: { [key: string]: any }; - event_data_template?: { [key: string]: any }; + event_data?: Record; + event_data_template?: Record; } export interface ServiceAction { service: string; entity_id?: string; - data?: { [key: string]: any }; + data?: Record; } export interface DeviceAction { diff --git a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts index 6d8ab80e97..23c3961378 100644 --- a/src/dialogs/config-flow/show-dialog-data-entry-flow.ts +++ b/src/dialogs/config-flow/show-dialog-data-entry-flow.ts @@ -23,7 +23,7 @@ export interface FlowConfig { handleFlowStep( hass: HomeAssistant, flowId: string, - data: { [key: string]: any } + data: Record ): Promise; deleteFlow(hass: HomeAssistant, flowId: string): Promise; diff --git a/src/dialogs/config-flow/step-flow-form.ts b/src/dialogs/config-flow/step-flow-form.ts index 660595b2f3..96aa5aeea3 100644 --- a/src/dialogs/config-flow/step-flow-form.ts +++ b/src/dialogs/config-flow/step-flow-form.ts @@ -34,7 +34,7 @@ class StepFlowForm extends LitElement { private _loading = false; @property() - private _stepData?: { [key: string]: any }; + private _stepData?: Record; @property() private _errorMsg?: string; diff --git a/src/external_app/external_messaging.ts b/src/external_app/external_messaging.ts index 58f19ce7db..1ad273d76c 100644 --- a/src/external_app/external_messaging.ts +++ b/src/external_app/external_messaging.ts @@ -40,7 +40,7 @@ type ExternalMessage = ExternalMessageResult | ExternalMessageResultError; export class ExternalMessaging { public commands: { [msgId: number]: CommandInFlight } = {}; - public cache: { [key: string]: any } = {}; + public cache: Record = {}; public msgId = 0; diff --git a/src/fake_data/entity.ts b/src/fake_data/entity.ts index 56d1240c74..78913353cb 100644 --- a/src/fake_data/entity.ts +++ b/src/fake_data/entity.ts @@ -21,9 +21,9 @@ export class Entity { public state: string; - public baseAttributes: HassEntityAttributeBase & { [key: string]: any }; + public baseAttributes: HassEntityAttributeBase & Record; - public attributes: HassEntityAttributeBase & { [key: string]: any }; + public attributes: HassEntityAttributeBase & Record; public hass?: any; @@ -39,7 +39,7 @@ export class Entity { this.attributes = baseAttributes; } - public async handleService(domain, service, data: { [key: string]: any }) { + public async handleService(domain, service, data: Record) { // eslint-disable-next-line console.log( `Unmocked service for ${this.entityId}: ${domain}/${service}`, diff --git a/src/fake_data/provide_hass.ts b/src/fake_data/provide_hass.ts index 3407ecbb18..ba4db6151e 100644 --- a/src/fake_data/provide_hass.ts +++ b/src/fake_data/provide_hass.ts @@ -20,7 +20,7 @@ type MockRestCallback = ( hass: MockHomeAssistant, method: string, path: string, - parameters: { [key: string]: any } | undefined + parameters: Record | undefined ) => any; export interface MockHomeAssistant extends HomeAssistant { @@ -35,7 +35,7 @@ export interface MockHomeAssistant extends HomeAssistant { ); mockAPI(path: string | RegExp, callback: MockRestCallback); mockEvent(event); - mockTheme(theme: { [key: string]: string } | null); + mockTheme(theme: Record | null); } export const provideHass = ( diff --git a/src/panels/config/automation/action/types/ha-automation-action-device_id.ts b/src/panels/config/automation/action/types/ha-automation-action-device_id.ts index f85b9d84ef..b75c5cce7b 100644 --- a/src/panels/config/automation/action/types/ha-automation-action-device_id.ts +++ b/src/panels/config/automation/action/types/ha-automation-action-device_id.ts @@ -40,7 +40,7 @@ export class HaDeviceAction extends LitElement { private _extraFieldsData = memoizeOne( (action: DeviceAction, capabilities: DeviceCapabilities) => { - const extraFieldsData: { [key: string]: any } = {}; + const extraFieldsData: Record = {}; capabilities.extra_fields.forEach((item) => { if (action[item.name] !== undefined) { extraFieldsData![item.name] = action[item.name]; diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-device.ts b/src/panels/config/automation/condition/types/ha-automation-condition-device.ts index a723ffd543..c60face55a 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-device.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-device.ts @@ -40,7 +40,7 @@ export class HaDeviceCondition extends LitElement { private _extraFieldsData = memoizeOne( (condition: DeviceCondition, capabilities: DeviceCapabilities) => { - const extraFieldsData: { [key: string]: any } = {}; + const extraFieldsData: Record = {}; capabilities.extra_fields.forEach((item) => { if (condition[item.name] !== undefined) { extraFieldsData![item.name] = condition[item.name]; diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts index 811efaa5fe..b5a6af9986 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts @@ -40,7 +40,7 @@ export class HaDeviceTrigger extends LitElement { private _extraFieldsData = memoizeOne( (trigger: DeviceTrigger, capabilities: DeviceCapabilities) => { - const extraFieldsData: { [key: string]: any } = {}; + const extraFieldsData: Record = {}; capabilities.extra_fields.forEach((item) => { if (trigger[item.name] !== undefined) { extraFieldsData![item.name] = trigger[item.name]; diff --git a/src/panels/lovelace/cards/hui-history-graph-card.ts b/src/panels/lovelace/cards/hui-history-graph-card.ts index db7f863998..bcd37e8386 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.ts +++ b/src/panels/lovelace/cards/hui-history-graph-card.ts @@ -56,7 +56,7 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { private _configEntities?: EntityConfig[]; - private _names: { [key: string]: string } = {}; + private _names: Record = {}; private _cacheConfig?: CacheConfig; diff --git a/src/panels/lovelace/cards/hui-map-card.ts b/src/panels/lovelace/cards/hui-map-card.ts index 8b226748ce..a1fb811d68 100644 --- a/src/panels/lovelace/cards/hui-map-card.ts +++ b/src/panels/lovelace/cards/hui-map-card.ts @@ -111,7 +111,7 @@ class HuiMapCard extends LitElement implements LovelaceCard { private _mapPaths: Array = []; - private _colorDict: { [key: string]: string } = {}; + private _colorDict: Record = {}; private _colorIndex = 0; diff --git a/src/panels/lovelace/entity-rows/types.ts b/src/panels/lovelace/entity-rows/types.ts index e1d328c330..729a986a15 100644 --- a/src/panels/lovelace/entity-rows/types.ts +++ b/src/panels/lovelace/entity-rows/types.ts @@ -17,7 +17,7 @@ export interface EntityFilterEntityConfig extends EntityConfig { } export interface DividerConfig { type: "divider"; - style: { [key: string]: string }; + style: Record; } export interface SectionConfig { type: "section"; @@ -38,7 +38,7 @@ export interface TextConfig { export interface CallServiceConfig extends EntityConfig { type: "call-service"; service: string; - service_data?: { [key: string]: any }; + service_data?: Record; action_name?: string; } export interface ButtonRowConfig extends EntityConfig { diff --git a/src/types.ts b/src/types.ts index 8911fac720..a16a66f31e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -98,7 +98,7 @@ export interface Theme { export interface Themes { default_theme: string; default_dark_theme: string | null; - themes: { [key: string]: Theme }; + themes: Record; darkMode: boolean; } @@ -188,7 +188,7 @@ export interface Notification { } export interface Resources { - [language: string]: { [key: string]: string }; + [language: string]: Record; } export interface Context { @@ -204,7 +204,7 @@ export interface ServiceCallResponse { export interface ServiceCallRequest { domain: string; service: string; - serviceData?: { [key: string]: any }; + serviceData?: Record; } export interface HomeAssistant { @@ -248,9 +248,9 @@ export interface HomeAssistant { callApi( method: "GET" | "POST" | "PUT" | "DELETE", path: string, - parameters?: { [key: string]: any } + parameters?: Record ): Promise; - fetchWithAuth(path: string, init?: { [key: string]: any }): Promise; + fetchWithAuth(path: string, init?: Record): Promise; sendWS(msg: MessageBase): void; callWS(msg: MessageBase): Promise; loadBackendTranslation(