mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Convert call-service to TypeScript (#1985)
* Convert call-service to TypeScript * Address Travis error * Address review comments
This commit is contained in:
parent
9ce74e2da1
commit
f9719957b0
@ -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);
|
||||
}
|
12
src/panels/lovelace/common/call-service.ts
Normal file
12
src/panels/lovelace/common/call-service.ts
Normal file
@ -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);
|
||||
};
|
@ -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
|
||||
|
@ -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!);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user