mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-29 12:16:39 +00:00
Add link to area on device page (#5396)
This commit is contained in:
parent
236bc6aefa
commit
525703d376
@ -97,6 +97,15 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private _computeArea = memoizeOne((areas, device):
|
||||||
|
| AreaRegistryEntry
|
||||||
|
| undefined => {
|
||||||
|
if (!areas || !device || !device.area_id) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return areas.find((area) => area.area_id === device.area_id);
|
||||||
|
});
|
||||||
|
|
||||||
private _batteryEntity = memoizeOne((entities: EntityRegistryEntry[]):
|
private _batteryEntity = memoizeOne((entities: EntityRegistryEntry[]):
|
||||||
| EntityRegistryEntry
|
| EntityRegistryEntry
|
||||||
| undefined => findBatteryEntity(this.hass, entities));
|
| undefined => findBatteryEntity(this.hass, entities));
|
||||||
@ -132,7 +141,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
const batteryState = batteryEntity
|
const batteryState = batteryEntity
|
||||||
? this.hass.states[batteryEntity.entity_id]
|
? this.hass.states[batteryEntity.entity_id]
|
||||||
: undefined;
|
: undefined;
|
||||||
const areaName = this._computeAreaName(this.areas, device);
|
const area = this._computeArea(this.areas, device);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-tabs-subpage
|
||||||
@ -165,12 +174,16 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
: html`
|
: html`
|
||||||
<div>
|
<div>
|
||||||
<h1>${computeDeviceName(device, this.hass)}</h1>
|
<h1>${computeDeviceName(device, this.hass)}</h1>
|
||||||
${areaName
|
${area
|
||||||
? this.hass.localize(
|
? html`
|
||||||
"ui.panel.config.integrations.config_entry.area",
|
<a href="/config/areas/area/${area.area_id}"
|
||||||
"area",
|
>${this.hass.localize(
|
||||||
areaName
|
"ui.panel.config.integrations.config_entry.area",
|
||||||
)
|
"area",
|
||||||
|
area.name || "Unnamed Area"
|
||||||
|
)}</a
|
||||||
|
>
|
||||||
|
`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
@ -437,13 +450,6 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
return state ? computeStateName(state) : null;
|
return state ? computeStateName(state) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeAreaName(areas, device): string | undefined {
|
|
||||||
if (!areas || !device || !device.area_id) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return areas.find((area) => area.area_id === device.area_id).name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _onImageLoad(ev) {
|
private _onImageLoad(ev) {
|
||||||
ev.target.style.display = "inline-block";
|
ev.target.style.display = "inline-block";
|
||||||
}
|
}
|
||||||
@ -648,6 +654,10 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
ha-card a {
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user