diff --git a/src/panels/lovelace/common/call-service.js b/src/panels/lovelace/common/call-service.js deleted file mode 100644 index 21c2b8e273..0000000000 --- a/src/panels/lovelace/common/call-service.js +++ /dev/null @@ -1,10 +0,0 @@ -export default function callService(config, hass) { - const entityId = config.entity; - const [domain, service] = config.service.split(".", 2); - const serviceData = Object.assign( - {}, - { entity_id: entityId }, - config.service_data - ); - hass.callService(domain, service, serviceData); -} diff --git a/src/panels/lovelace/common/call-service.ts b/src/panels/lovelace/common/call-service.ts new file mode 100644 index 0000000000..de3b39984b --- /dev/null +++ b/src/panels/lovelace/common/call-service.ts @@ -0,0 +1,12 @@ +import { HomeAssistant } from "../../../types"; +import { CallServiceConfig } from "../entity-rows/types"; + +export const callService = ( + config: CallServiceConfig, + hass: HomeAssistant +): void => { + const entityId = config.entity; + const [domain, service] = config.service.split(".", 2); + const serviceData = { entity_id: entityId, ...config.service_data }; + hass.callService(domain, service, serviceData); +}; diff --git a/src/panels/lovelace/entity-rows/types.ts b/src/panels/lovelace/entity-rows/types.ts index 648b9cf9cb..b2c7d272cf 100644 --- a/src/panels/lovelace/entity-rows/types.ts +++ b/src/panels/lovelace/entity-rows/types.ts @@ -16,12 +16,10 @@ export interface WeblinkConfig { icon?: string; url: string; } -export interface CallServiceConfig { - name: string; - icon?: string; +export interface CallServiceConfig extends EntityConfig { action_name?: string; service: string; - service_data?: string; + service_data?: { [key: string]: any }; } export type EntityRowConfig = | EntityConfig diff --git a/src/panels/lovelace/special-rows/hui-call-service-row.ts b/src/panels/lovelace/special-rows/hui-call-service-row.ts index 4ac0d03ff4..b0aa0222ba 100644 --- a/src/panels/lovelace/special-rows/hui-call-service-row.ts +++ b/src/panels/lovelace/special-rows/hui-call-service-row.ts @@ -3,7 +3,7 @@ import "@polymer/paper-button/paper-button"; import "../../../components/ha-icon"; -import callService from "../common/call-service"; +import { callService } from "../common/call-service"; import { EntityRow, CallServiceConfig } from "../entity-rows/types"; import { HomeAssistant } from "../../../types"; import { TemplateResult } from "lit-html"; @@ -80,7 +80,7 @@ class HuiCallServiceRow extends LitElement implements EntityRow { } private _callService() { - callService(this._config, this.hass); + callService(this._config!, this.hass!); } }