Skip to content
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
65 changes: 0 additions & 65 deletions src/components/buttons/ha-call-api-button.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/components/buttons/ha-call-api-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { css, CSSResult, html, LitElement, property, query } from "lit-element";
import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types";
import "./ha-progress-button";

class HaCallApiButton extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@property() public method: "POST" | "GET" | "PUT" | "DELETE" = "POST";

@property() public data = {};

@property({ type: Boolean, reflect: true }) public disabled = false;

@property({ type: Boolean }) public progress = false;

@property() public path?: string;

@query("ha-progress-button", true) private _progressButton;

render() {
return html`
<ha-progress-button
.progress=${this.progress}
@click=${this._buttonTapped}
?disabled=${this.disabled}
><slot></slot
></ha-progress-button>
`;
}

async _buttonTapped() {
this.progress = true;
const eventData: {
method: string;
path: string;
data: any;
success?: boolean;
response?: any;
} = {
method: this.method,
path: this.path!,
data: this.data,
};

try {
const resp = await this.hass.callApi(this.method, this.path!, this.data);
this.progress = false;
this._progressButton.actionSuccess();
eventData.success = true;
eventData.response = resp;
} catch (err) {
this.progress = false;
this._progressButton.actionError();
eventData.success = false;
eventData.response = err;
}

fireEvent(this, "hass-api-called", eventData as any);
}

static get styles(): CSSResult {
return css`
:host([disabled]) {
pointer-events: none;
}
`;
}
}

customElements.define("ha-call-api-button", HaCallApiButton);

declare global {
interface HTMLElementTagNameMap {
"ha-call-api-button": HaCallApiButton;
}
}
1 change: 1 addition & 0 deletions src/data/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface CloudPreferences {

export type CloudStatusLoggedIn = CloudStatusBase & {
email: string;
google_registered: boolean;
google_entities: EntityFilter;
google_domains: string[];
alexa_entities: EntityFilter;
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/cloud/account/cloud-alexa-pref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class CloudAlexaPref extends LitElement {
.switch {
position: absolute;
right: 24px;
top: 32px;
top: 24px;
}
:host([dir="rtl"]) .switch {
right: auto;
Expand Down
Loading