Allow Google unlocking locks (#2073)

* Allow Google unlocking locks

* Fix missing type
This commit is contained in:
Paulus Schoutsen 2018-11-20 23:23:12 +01:00 committed by GitHub
parent c01bd57ba5
commit 2ca3a784e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 8 deletions

View File

@ -24,7 +24,7 @@ export class CloudAlexaPref extends LitElement {
}
protected render(): TemplateResult {
const enabled = this.cloudStatus!.alexa_enabled;
const enabled = this.cloudStatus!.prefs.alexa_enabled;
return html`
${this.renderStyle()}

View File

@ -25,13 +25,14 @@ export class CloudGooglePref extends LitElement {
}
protected render(): TemplateResult {
const enabled = this.cloudStatus!.google_enabled;
const { google_enabled, google_allow_unlock } = this.cloudStatus!.prefs;
return html`
${this.renderStyle()}
<paper-card heading="Google Assistant">
<paper-toggle-button
.checked="${enabled}"
id="google_enabled"
.checked="${google_enabled}"
@change="${this._toggleChanged}"
></paper-toggle-button>
<div class="card-content">
@ -61,8 +62,16 @@ export class CloudGooglePref extends LitElement {
the Google Home or Android phone.</em
>
${
enabled
google_enabled
? html`
<div class="unlock">
<div>Allow unlocking locks</div>
<paper-toggle-button
id="google_allow_unlock"
.checked="${google_allow_unlock}"
@change="${this._toggleChanged}"
></paper-toggle-button>
</div>
<p>Exposed entities:</p>
<cloud-exposed-entities
.hass="${this.hass}"
@ -76,7 +85,7 @@ export class CloudGooglePref extends LitElement {
<div class="card-actions">
<ha-call-api-button
.hass="${this.hass}"
.disabled="${!enabled}"
.disabled="${!google_enabled}"
path="cloud/google_actions/sync"
>Sync devices</ha-call-api-button
>
@ -88,7 +97,7 @@ export class CloudGooglePref extends LitElement {
private async _toggleChanged(ev) {
const toggle = ev.target as PaperToggleButtonElement;
try {
await updatePref(this.hass!, { google_enabled: toggle.checked! });
await updatePref(this.hass!, { [toggle.id]: toggle.checked! });
fireEvent(this, "ha-refresh-cloud-status");
} catch (err) {
toggle.checked = !toggle.checked;
@ -110,6 +119,14 @@ export class CloudGooglePref extends LitElement {
color: var(--primary-color);
font-weight: 500;
}
.unlock {
display: flex;
flex-direction: row;
padding-top: 16px;
}
.unlock > div {
flex: 1;
}
</style>
`;
}

View File

@ -9,6 +9,7 @@ export const updatePref = (
prefs: {
google_enabled?: boolean;
alexa_enabled?: boolean;
google_allow_unlock?: boolean;
}
) =>
hass.callWS({

View File

@ -11,12 +11,15 @@ interface CloudStatusBase {
export type CloudStatusLoggedIn = CloudStatusBase & {
email: string;
google_enabled: boolean;
google_entities: EntityFilter;
google_domains: string[];
alexa_enabled: boolean;
alexa_entities: EntityFilter;
alexa_domains: string[];
prefs: {
google_enabled: boolean;
alexa_enabled: boolean;
google_allow_unlock: boolean;
};
};
export type CloudStatus = CloudStatusBase | CloudStatusLoggedIn;