mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 16:26:43 +00:00
Request tiny thumbnails for cameras in the entity selector to reduce memory pressure (#12880)
This commit is contained in:
parent
75562efb79
commit
91cd584b4b
@ -12,8 +12,10 @@ import { property, state } from "lit/decorators";
|
|||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import { computeActiveState } from "../../common/entity/compute_active_state";
|
import { computeActiveState } from "../../common/entity/compute_active_state";
|
||||||
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { iconColorCSS } from "../../common/style/icon_color_css";
|
import { iconColorCSS } from "../../common/style/icon_color_css";
|
||||||
|
import { cameraUrlWithWidthHeight } from "../../data/camera";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-state-icon";
|
import "../ha-state-icon";
|
||||||
|
|
||||||
@ -93,6 +95,9 @@ export class StateBadge extends LitElement {
|
|||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
imageUrl = this.hass.hassUrl(imageUrl);
|
imageUrl = this.hass.hassUrl(imageUrl);
|
||||||
}
|
}
|
||||||
|
if (computeDomain(stateObj.entity_id) === "camera") {
|
||||||
|
imageUrl = cameraUrlWithWidthHeight(imageUrl, 80, 80);
|
||||||
|
}
|
||||||
hostStyle.backgroundImage = `url(${imageUrl})`;
|
hostStyle.backgroundImage = `url(${imageUrl})`;
|
||||||
this._showIcon = false;
|
this._showIcon = false;
|
||||||
} else if (stateObj.state === "on") {
|
} else if (stateObj.state === "on") {
|
||||||
|
@ -41,6 +41,12 @@ export interface WebRtcAnswer {
|
|||||||
answer: string;
|
answer: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const cameraUrlWithWidthHeight = (
|
||||||
|
base_url: string,
|
||||||
|
width: number,
|
||||||
|
height: number
|
||||||
|
) => `${base_url}&width=${width}&height=${height}`;
|
||||||
|
|
||||||
export const computeMJPEGStreamUrl = (entity: CameraEntity) =>
|
export const computeMJPEGStreamUrl = (entity: CameraEntity) =>
|
||||||
`/api/camera_proxy_stream/${entity.entity_id}?token=${entity.attributes.access_token}`;
|
`/api/camera_proxy_stream/${entity.entity_id}?token=${entity.attributes.access_token}`;
|
||||||
|
|
||||||
@ -57,7 +63,7 @@ export const fetchThumbnailUrlWithCache = async (
|
|||||||
hass,
|
hass,
|
||||||
entityId
|
entityId
|
||||||
);
|
);
|
||||||
return `${base_url}&width=${width}&height=${height}`;
|
return cameraUrlWithWidthHeight(base_url, width, height);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchThumbnailUrl = async (
|
export const fetchThumbnailUrl = async (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user