From ff80eef25d6f20bcaf9b2d8b9fc530a5394b88bd Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Wed, 24 Jul 2019 23:05:33 -0400 Subject: [PATCH 01/18] Update ZHA device card (#3411) * add ability to subscribe to individual updates * catch changes on area, device name and entity ids * subscribe directly * remove entity registry change * add type * remove device subscription --- src/panels/config/zha/zha-device-card.ts | 50 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/panels/config/zha/zha-device-card.ts b/src/panels/config/zha/zha-device-card.ts index 19d0e94b77..b34a720bff 100644 --- a/src/panels/config/zha/zha-device-card.ts +++ b/src/panels/config/zha/zha-device-card.ts @@ -30,13 +30,18 @@ import { DeviceRegistryEntryMutableParams, updateDeviceRegistryEntry, } from "../../../data/device_registry"; -import { reconfigureNode, ZHADevice } from "../../../data/zha"; +import { + reconfigureNode, + ZHADevice, + ZHAEntityReference, +} from "../../../data/zha"; import { haStyle } from "../../../resources/styles"; import { HomeAssistant } from "../../../types"; import { ItemSelectedEvent, NodeServiceData } from "./types"; import { navigate } from "../../../common/navigate"; -import { UnsubscribeFunc } from "home-assistant-js-websocket"; +import { UnsubscribeFunc, HassEvent } from "home-assistant-js-websocket"; import { formatAsPaddedHex } from "./functions"; +import computeStateName from "../../../common/entity/compute_state_name"; declare global { // for fire event @@ -60,12 +65,34 @@ class ZHADeviceCard extends LitElement { @property() private _selectedAreaIndex: number = -1; @property() private _userGivenName?: string; private _unsubAreas?: UnsubscribeFunc; + private _unsubEntities?: UnsubscribeFunc; public disconnectedCallback() { super.disconnectedCallback(); if (this._unsubAreas) { this._unsubAreas(); } + if (this._unsubEntities) { + this._unsubEntities(); + } + } + + public connectedCallback() { + super.connectedCallback(); + this._unsubAreas = subscribeAreaRegistry(this.hass.connection, (areas) => { + this._areas = areas; + }); + this.hass.connection + .subscribeEvents((event: HassEvent) => { + if (this.device) { + this.device!.entities.forEach((deviceEntity) => { + if (event.data.old_entity_id === deviceEntity.entity_id) { + deviceEntity.entity_id = event.data.entity_id; + } + }); + } + }, "entity_registry_updated") + .then((unsub) => (this._unsubEntities = unsub)); } protected firstUpdated(changedProperties: PropertyValues): void { @@ -90,14 +117,6 @@ class ZHADeviceCard extends LitElement { } this._userGivenName = this.device!.user_given_name; } - if (!this._unsubAreas) { - this._unsubAreas = subscribeAreaRegistry( - this.hass.connection, - (areas) => { - this._areas = areas; - } - ); - } super.update(changedProperties); } @@ -168,7 +187,9 @@ class ZHADeviceCard extends LitElement { ${!this.isJoinPage ? html` -
${entity.name}
+
+ ${this._computeEntityName(entity)} +
${entity.entity_id}
@@ -280,6 +301,13 @@ class ZHADeviceCard extends LitElement { } } + private _computeEntityName(entity: ZHAEntityReference): string { + if (this.hass.states[entity.entity_id]) { + return computeStateName(this.hass.states[entity.entity_id]); + } + return entity.name; + } + private async _saveCustomName(event): Promise { if (this.hass) { const values: DeviceRegistryEntryMutableParams = { From 87293e4b152544fdb4939cb39071fb3afcb08791 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 25 Jul 2019 10:14:05 -0700 Subject: [PATCH 02/18] Add more labels (#3422) --- src/dialogs/more-info/more-info-controls.js | 3 ++- src/layouts/hass-subpage.ts | 1 + src/panels/lovelace/hui-root.ts | 30 ++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/dialogs/more-info/more-info-controls.js b/src/dialogs/more-info/more-info-controls.js index 0410fa6107..849a4a1452 100644 --- a/src/dialogs/more-info/more-info-controls.js +++ b/src/dialogs/more-info/more-info-controls.js @@ -68,8 +68,9 @@ class MoreInfoControls extends EventsMixin(PolymerElement) {
[[_computeStateName(stateObj)]] diff --git a/src/layouts/hass-subpage.ts b/src/layouts/hass-subpage.ts index be0ec53370..2e0befb405 100644 --- a/src/layouts/hass-subpage.ts +++ b/src/layouts/hass-subpage.ts @@ -22,6 +22,7 @@ class HassSubpage extends LitElement { return html`
diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index 9c959ade8f..b61eef4071 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -154,28 +154,46 @@ class HUIRoot extends LitElement { > ${this._yamlMode ? html` - ${this.hass!.localize( + + ${this.hass!.localize( + "ui.panel.lovelace.menu.refresh" + )} + ` : ""} ${__DEMO__ /* No unused entities available in the demo */ ? "" : html` - + ${this.hass!.localize( "ui.panel.lovelace.menu.unused_entities" )} `} - ${this.hass!.localize( "ui.panel.lovelace.menu.configure_ui" )} - ${this.hass!.localize( "ui.panel.lovelace.menu.help" )} Date: Thu, 25 Jul 2019 10:14:13 -0700 Subject: [PATCH 03/18] Add aria labels to cover controls (#3421) --- src/components/ha-cover-controls.js | 3 +++ src/components/ha-cover-tilt-controls.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/components/ha-cover-controls.js b/src/components/ha-cover-controls.js index 2c35960fe5..76aa911755 100644 --- a/src/components/ha-cover-controls.js +++ b/src/components/ha-cover-controls.js @@ -18,17 +18,20 @@ class HaCoverControls extends PolymerElement {
Date: Thu, 25 Jul 2019 10:14:20 -0700 Subject: [PATCH 04/18] Show notification indicator in forced mobile mode (#3420) --- src/components/ha-menu-button.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/ha-menu-button.ts b/src/components/ha-menu-button.ts index 8a99bafea9..291e48eadb 100644 --- a/src/components/ha-menu-button.ts +++ b/src/components/ha-menu-button.ts @@ -44,7 +44,7 @@ class HaMenuButton extends LitElement { protected render(): TemplateResult | void { const hasNotifications = - this.narrow && + (this.narrow || this.hass.dockedSidebar === "always_hidden") && (this._hasNotifications || Object.keys(this.hass.states).some( (entityId) => computeDomain(entityId) === "configurator" @@ -131,9 +131,10 @@ class HaMenuButton extends LitElement { background-color: var(--accent-color); width: 12px; height: 12px; - top: 8px; - right: 5px; + top: 5px; + right: 2px; border-radius: 50%; + border: 2px solid var(--primary-color); } `; } From dae0ecce6a0d6ce807046dc987f8c97ac9777558 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 25 Jul 2019 10:14:29 -0700 Subject: [PATCH 05/18] Hide preset=none (#3419) * Hide preset=none * Add const to commit --- src/components/ha-climate-state.js | 9 ++++++++- src/data/climate.ts | 2 ++ src/panels/lovelace/cards/hui-thermostat-card.ts | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/ha-climate-state.js b/src/components/ha-climate-state.js index e000a27650..569014fcc8 100644 --- a/src/components/ha-climate-state.js +++ b/src/components/ha-climate-state.js @@ -2,6 +2,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag"; import { PolymerElement } from "@polymer/polymer/polymer-element"; import LocalizeMixin from "../mixins/localize-mixin"; +import { CLIMATE_PRESET_NONE } from "../data/climate"; /* * @appliesMixin LocalizeMixin @@ -40,7 +41,7 @@ class HaClimateState extends LocalizeMixin(PolymerElement) {