Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert call-service to TypeScript #1985

Merged
merged 3 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/panels/lovelace/common/call-service.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/panels/lovelace/common/call-service.ts
Original file line number Diff line number Diff line change
@@ -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);
};
6 changes: 2 additions & 4 deletions src/panels/lovelace/entity-rows/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/special-rows/hui-call-service-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -80,7 +80,7 @@ class HuiCallServiceRow extends LitElement implements EntityRow {
}

private _callService() {
callService(this._config, this.hass);
callService(this._config!, this.hass!);
}
}

Expand Down