diff --git a/src/panels/config/devices/device-detail/ha-device-card.js b/src/panels/config/devices/device-detail/ha-device-card.js deleted file mode 100644 index 94ee330e7e..0000000000 --- a/src/panels/config/devices/device-detail/ha-device-card.js +++ /dev/null @@ -1,157 +0,0 @@ -import { html } from "@polymer/polymer/lib/utils/html-tag"; -import { PolymerElement } from "@polymer/polymer/polymer-element"; - -import "../../../../components/ha-card"; - -import { EventsMixin } from "../../../../mixins/events-mixin"; -import LocalizeMixin from "../../../../mixins/localize-mixin"; -import { compare } from "../../../../common/string/compare"; -import { updateDeviceRegistryEntry } from "../../../../data/device_registry"; -import { - loadDeviceRegistryDetailDialog, - showDeviceRegistryDetailDialog, -} from "../../../../dialogs/device-registry-detail/show-dialog-device-registry-detail"; - -/* - * @appliesMixin EventsMixin - */ -class HaDeviceCard extends EventsMixin(LocalizeMixin(PolymerElement)) { - static get template() { - return html` - - -
-
-
[[device.model]]
-
- [[localize('ui.panel.config.integrations.config_entry.manuf', - 'manufacturer', device.manufacturer)]] -
- -
- - -
-
- `; - } - - static get properties() { - return { - device: Object, - devices: Array, - areas: Array, - hass: Object, - narrow: { - type: Boolean, - reflectToAttribute: true, - }, - _childDevices: { - type: Array, - computed: "_computeChildDevices(device, devices)", - }, - }; - } - - firstUpdated(changedProps) { - super.firstUpdated(changedProps); - loadDeviceRegistryDetailDialog(); - } - - _computeArea(areas, device) { - if (!areas || !device || !device.area_id) { - return "No Area"; - } - // +1 because of "No Area" entry - return areas.find((area) => area.area_id === device.area_id).name; - } - - _computeChildDevices(device, devices) { - return devices - .filter((dev) => dev.via_device_id === device.id) - .sort((dev1, dev2) => compare(dev1.name, dev2.name)); - } - - _deviceName(device) { - return device.name_by_user || device.name; - } - - _computeDeviceName(devices, deviceId) { - const device = devices.find((dev) => dev.id === deviceId); - return device - ? this._deviceName(device) - : `(${this.localize( - "ui.panel.config.integrations.config_entry.device_unavailable" - )})`; - } - - _gotoSettings() { - const device = this.device; - showDeviceRegistryDetailDialog(this, { - device, - updateEntry: async (updates) => { - await updateDeviceRegistryEntry(this.hass, device.id, updates); - }, - }); - } - - _openMoreInfo(ev) { - this.fire("hass-more-info", { entityId: ev.model.entity.entity_id }); - } -} - -customElements.define("ha-device-card", HaDeviceCard); diff --git a/src/panels/config/devices/device-detail/ha-device-card.ts b/src/panels/config/devices/device-detail/ha-device-card.ts new file mode 100644 index 0000000000..86e3109793 --- /dev/null +++ b/src/panels/config/devices/device-detail/ha-device-card.ts @@ -0,0 +1,132 @@ +import "../../../../components/ha-card"; + +import { DeviceRegistryEntry } from "../../../../data/device_registry"; +import { loadDeviceRegistryDetailDialog } from "../../../../dialogs/device-registry-detail/show-dialog-device-registry-detail"; +import { + LitElement, + html, + customElement, + property, + TemplateResult, + CSSResult, + css, +} from "lit-element"; +import { HomeAssistant } from "../../../../types"; +import { AreaRegistryEntry } from "../../../../data/area_registry"; + +@customElement("ha-device-card") +export class HaDeviceCard extends LitElement { + @property() public hass!: HomeAssistant; + @property() public device!: DeviceRegistryEntry; + @property() public devices!: DeviceRegistryEntry[]; + @property() public areas!: AreaRegistryEntry[]; + @property() public narrow!: boolean; + + protected render(): TemplateResult { + return html` + +
+
+
${this.device.model}
+
+ ${this.hass.localize( + "ui.panel.config.integrations.config_entry.manuf", + "manufacturer", + this.device.manufacturer + )} +
+ ${this.device.area_id + ? html` +
+
+ ${this.hass.localize( + "ui.panel.config.integrations.config_entry.area", + "area", + this._computeArea(this.areas, this.device) + )} +
+
+ ` + : ""} +
+ ${this.device.via_device_id + ? html` +
+ ${this.hass.localize( + "ui.panel.config.integrations.config_entry.via" + )} + ${this._computeDeviceName( + this.devices, + this.device.via_device_id + )} +
+ ` + : ""} + ${this.device.sw_version + ? html` +
+ ${this.hass.localize( + "ui.panel.config.integrations.config_entry.firmware", + "version", + this.device.sw_version + )} +
+ ` + : ""} +
+
+ `; + } + + protected firstUpdated(changedProps) { + super.firstUpdated(changedProps); + loadDeviceRegistryDetailDialog(); + } + + private _computeArea(areas, device) { + if (!areas || !device || !device.area_id) { + return "No Area"; + } + // +1 because of "No Area" entry + return areas.find((area) => area.area_id === device.area_id).name; + } + + private _deviceName(device) { + return device.name_by_user || device.name; + } + + private _computeDeviceName(devices, deviceId) { + const device = devices.find((dev) => dev.id === deviceId); + return device + ? this._deviceName(device) + : `(${this.hass.localize( + "ui.panel.config.integrations.config_entry.device_unavailable" + )})`; + } + + static get styles(): CSSResult { + return css` + ha-card { + flex: 1 0 100%; + padding-bottom: 10px; + min-width: 0; + } + .device { + width: 30%; + } + .area { + color: var(--primary-text-color); + } + .extra-info { + margin-top: 8px; + } + .manuf, + .entity-id, + .model { + color: var(--secondary-text-color); + } + `; + } +} diff --git a/src/panels/config/devices/device-detail/ha-device-entities-card.ts b/src/panels/config/devices/device-detail/ha-device-entities-card.ts index 686d840e49..3b19563b86 100644 --- a/src/panels/config/devices/device-detail/ha-device-entities-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-entities-card.ts @@ -62,6 +62,7 @@ export class HaDeviceEntitiesCard extends LitElement { ${stateObj ? html` @@ -72,7 +73,7 @@ export class HaDeviceEntitiesCard extends LitElement { .icon=${domainIcon(computeDomain(entry.entity_id))} > `} - +
${entry.stateName}
${entry.entity_id}
@@ -139,6 +140,12 @@ export class HaDeviceEntitiesCard extends LitElement { .disabled-entry { color: var(--secondary-text-color); } + state-badge { + cursor: pointer; + } + paper-icon-item:not(.disabled-entry) paper-item-body { + cursor: pointer; + } `; } } diff --git a/src/translations/en.json b/src/translations/en.json index 03fab1fae2..984a9ffa1d 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1204,6 +1204,7 @@ "firmware": "Firmware: {version}", "device_unavailable": "device unavailable", "entity_unavailable": "entity unavailable", + "area": "In {area}", "no_area": "No Area" }, "config_flow": {