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
7 changes: 6 additions & 1 deletion src/components/ha-start-voice-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
import EventsMixin from "../mixins/events-mixin";

import isComponentLoaded from "../common/config/is_component_loaded";
import { fireEvent } from "../common/dom/fire_event";

/*
* @appliesMixin EventsMixin
Expand Down Expand Up @@ -43,7 +44,11 @@ class HaStartVoiceButton extends EventsMixin(PolymerElement) {
}

handleListenClick() {
this.fire("hass-start-voice");
fireEvent(this, "show-dialog", {
dialogImport: () =>
import(/* webpackChunkName: "voice-command-dialog" */ "../dialogs/ha-voice-command-dialog"),
dialogTag: "ha-voice-command-dialog",
});
}
}

Expand Down
16 changes: 5 additions & 11 deletions src/data/ws-user.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {
createCollection,
getUser,
Connection,
getCollection,
} from "home-assistant-js-websocket";
import { User } from "../types";

export const userCollection = (conn: Connection) =>
getCollection(conn, "_usr", () => getUser(conn) as Promise<User>, undefined);

export const subscribeUser = (
conn: Connection,
onChange: (user: User) => void
) =>
createCollection<User>(
"_usr",
// the getUser command is mistyped in current verrsion of HAWS.
// Fixed in 3.2.5
() => (getUser(conn) as unknown) as Promise<User>,
undefined,
conn,
onChange
);
) => userCollection(conn).subscribe(onChange);
4 changes: 4 additions & 0 deletions src/dialogs/ha-voice-command-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class HaVoiceCommandDialog extends DialogMixin(PolymerElement) {
return ["dialogOpenChanged(opened)"];
}

showDialog() {
this.opened = true;
}

initRecognition() {
/* eslint-disable new-cap */
this.recognition = new webkitSpeechRecognition();
Expand Down
10 changes: 0 additions & 10 deletions src/entrypoints/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Load polyfill first so HTML imports start resolving
/* eslint-disable import/first */
import "../resources/html-import/polyfill";
import "@polymer/app-route/app-location";
import "@polymer/app-route/app-route";
import "@polymer/iron-flex-layout/iron-flex-layout-classes";
import "@polymer/paper-styles/typography";
import { setPassiveTouchGestures } from "@polymer/polymer/lib/utils/settings";

Expand All @@ -16,13 +13,6 @@ import "../components/ha-iconset-svg";

import "../layouts/app/home-assistant";

/* polyfill for paper-dropdown */
setTimeout(
() =>
import(/* webpackChunkName: "polyfill-web-animations-next" */ "web-animations-js/web-animations-next-lite.min"),
2000
);

setPassiveTouchGestures(true);
/* LastPass createElement workaround. See #428 */
document.createElement = Document.prototype.createElement;
44 changes: 0 additions & 44 deletions src/layouts/app/auth-mixin.js

This file was deleted.

55 changes: 55 additions & 0 deletions src/layouts/app/auth-mixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { clearState } from "../../util/ha-pref-storage";
import { askWrite } from "../../common/auth/token_storage";
import { subscribeUser, userCollection } from "../../data/ws-user";
import { Constructor, LitElement } from "lit-element";
import { HassBaseEl } from "./hass-base-mixin";

declare global {
// for fire event
interface HASSDomEvents {
"hass-refresh-current-user": undefined;
}
}

export default (superClass: Constructor<LitElement & HassBaseEl>) =>
class extends superClass {
protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
this.addEventListener("hass-logout", () => this._handleLogout());
this.addEventListener("hass-refresh-current-user", () => {
userCollection(this.hass!.connection).refresh();
});
}

protected hassConnected() {
super.hassConnected();
subscribeUser(this.hass!.connection, (user) =>
this._updateHass({ user })
);

if (askWrite()) {
this.updateComplete
.then(() =>
import(/* webpackChunkName: "ha-store-auth-card" */ "../../dialogs/ha-store-auth-card")
)
.then(() => {
const el = document.createElement("ha-store-auth-card");
this.shadowRoot!.appendChild(el);
this.provideHass(el);
});
}
}

private async _handleLogout() {
try {
await this.hass!.auth.revoke();
this.hass!.connection.close();
clearState();
document.location.href = "/";
} catch (err) {
// tslint:disable-next-line
console.error(err);
alert("Log out failed");
}
}
};
5 changes: 4 additions & 1 deletion src/layouts/app/home-assistant.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "@polymer/app-route/app-location";
import "@polymer/iron-flex-layout/iron-flex-layout-classes";
import {
html,
LitElement,
PropertyDeclarations,
PropertyValues,
css,
} from "lit-element";

import "../home-assistant-main";
Expand All @@ -27,6 +27,7 @@ import { Route, HomeAssistant } from "../../types";
import { navigate } from "../../common/navigate";

(LitElement.prototype as any).html = html;
(LitElement.prototype as any).css = css;

const ext = <T>(baseClass: T, mixins): T =>
mixins.reduceRight((base, mixin) => mixin(base), baseClass);
Expand Down Expand Up @@ -82,6 +83,8 @@ export class HomeAssistantAppEl extends ext(HassBaseMixin(LitElement), [
protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
setTimeout(registerServiceWorker, 1000);
/* polyfill for paper-dropdown */
import(/* webpackChunkName: "polyfill-web-animations-next" */ "web-animations-js/web-animations-next-lite.min");
}

protected updated(changedProps: PropertyValues): void {
Expand Down
23 changes: 0 additions & 23 deletions src/layouts/app/more-info-mixin.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/layouts/app/more-info-mixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Constructor, LitElement } from "lit-element";

import { HassBaseEl } from "./hass-base-mixin";

declare global {
// for fire event
interface HASSDomEvents {
"hass-more-info": {
entityId: string;
};
}
}

export default (superClass: Constructor<LitElement & HassBaseEl>) =>
class extends superClass {
private _moreInfoEl?: any;

protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
this.addEventListener("hass-more-info", (e) => this._handleMoreInfo(e));

// Load it once we are having the initial rendering done.
import(/* webpackChunkName: "more-info-dialog" */ "../../dialogs/ha-more-info-dialog");
}

private async _handleMoreInfo(ev) {
if (!this._moreInfoEl) {
this._moreInfoEl = document.createElement("ha-more-info-dialog");
this.shadowRoot!.appendChild(this._moreInfoEl);
this.provideHass(this._moreInfoEl);
}
this._updateHass({ moreInfoEntityId: ev.detail.entityId });
}
};
13 changes: 2 additions & 11 deletions src/layouts/home-assistant-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import { HomeAssistant, Route } from "../types";
import { fireEvent } from "../common/dom/fire_event";
import { PolymerChangedEvent } from "../polymer-types";

import(/* webpackChunkName: "ha-sidebar" */ "../components/ha-sidebar");
import(/* webpackChunkName: "voice-command-dialog" */ "../dialogs/ha-voice-command-dialog");

const NON_SWIPABLE_PANELS = ["kiosk", "map"];

class HomeAssistantMain extends LitElement {
Expand All @@ -51,7 +48,6 @@ class HomeAssistantMain extends LitElement {

return html`
<ha-url-sync .hass=${hass}></ha-url-sync>
<ha-voice-command-dialog .hass=${hass}></ha-voice-command-dialog>
<iron-media-query
query="(max-width: 870px)"
query-matches-changed=${this._narrowChanged}
Expand Down Expand Up @@ -84,6 +80,8 @@ class HomeAssistantMain extends LitElement {
}

protected firstUpdated() {
import(/* webpackChunkName: "ha-sidebar" */ "../components/ha-sidebar");

this.addEventListener("hass-open-menu", () => {
if (this._narrow) {
this.drawer.open();
Expand All @@ -97,9 +95,6 @@ class HomeAssistantMain extends LitElement {
fireEvent(this, "hass-dock-sidebar", { dock: false });
}
});
this.addEventListener("hass-start-voice", () => {
(this.voiceDialog as any).opened = true;
});
}

protected updated(changedProps: PropertyValues) {
Expand All @@ -125,10 +120,6 @@ class HomeAssistantMain extends LitElement {
return this.shadowRoot!.querySelector("app-drawer")!;
}

private get voiceDialog() {
return this.shadowRoot!.querySelector("ha-voice-command-dialog")!;
}

static get styles(): CSSResult {
return css`
:host {
Expand Down