mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-01 09:09:11 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57d73d236f | ||
|
|
336259f6d2 | ||
|
|
1882e154fe | ||
|
|
baa067caf0 | ||
|
|
07b5d9e98c | ||
|
|
f2b2c92bdd | ||
|
|
33ef19dac1 | ||
|
|
1e797c345c | ||
|
|
9083641ae7 | ||
|
|
5fc4ad4e0c | ||
|
|
ba33d2897b | ||
|
|
9484d51694 | ||
|
|
55739f2666 |
No files matched your search
+5
-5
@@ -40,7 +40,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "8.1.3",
|
||||
"@babel/runtime": "8.1.4",
|
||||
"@braintree/sanitize-url": "7.1.2",
|
||||
"@codemirror/autocomplete": "6.20.4",
|
||||
"@codemirror/commands": "6.11.2",
|
||||
@@ -136,13 +136,13 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ampproject/remapping": "2.3.0",
|
||||
"@babel/core": "8.1.3",
|
||||
"@babel/core": "8.1.4",
|
||||
"@babel/helper-compilation-targets": "8.0.7",
|
||||
"@babel/helper-define-polyfill-provider": "1.0.0",
|
||||
"@babel/plugin-transform-class-properties": "8.0.1",
|
||||
"@babel/plugin-transform-private-methods": "8.0.1",
|
||||
"@babel/plugin-transform-runtime": "8.1.2",
|
||||
"@babel/preset-env": "8.0.7",
|
||||
"@babel/preset-env": "8.1.4",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.23.1",
|
||||
"@eslint/js": "10.0.1",
|
||||
"@gfx/zopfli": "1.0.15",
|
||||
@@ -177,7 +177,7 @@
|
||||
"browserslist-useragent-regexp": "4.1.4",
|
||||
"core-js-compat": "3.51.0",
|
||||
"del": "9.0.1",
|
||||
"eslint": "10.15.0",
|
||||
"eslint": "10.16.0",
|
||||
"eslint-config-prettier": "10.1.9",
|
||||
"eslint-import-resolver-webpack": "0.13.11",
|
||||
"eslint-plugin-import-x": "4.18.1",
|
||||
@@ -222,7 +222,7 @@
|
||||
"webpackbar": "7.0.0",
|
||||
"workbox-build": "7.4.1"
|
||||
},
|
||||
"packageManager": "[email protected]3.0",
|
||||
"packageManager": "[email protected]4.0",
|
||||
"volta": {
|
||||
"node": "24.22.3"
|
||||
}
|
||||
|
||||
Generated
+521
-526
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,74 @@
|
||||
import type { ReactiveControllerHost } from "@lit/reactive-element/reactive-controller";
|
||||
import type {
|
||||
ConditionContext,
|
||||
VisibilityCondition,
|
||||
} from "../../panels/lovelace/common/validate-condition";
|
||||
import { addEntityToCondition } from "../../panels/lovelace/common/validate-condition";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import type { ConditionEvaluation } from "../controllers/condition-evaluator-controller";
|
||||
import { ConditionEvaluatorController } from "../controllers/condition-evaluator-controller";
|
||||
import { dropInvalidConditions } from "./sanitize";
|
||||
|
||||
export interface VisibilitySubscription {
|
||||
/** Pass each new hass object so client-side conditions check again. */
|
||||
update(hass: HomeAssistant): void;
|
||||
/** Close the subscriptions. `onChange` is not called again. */
|
||||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Live visibility of a list of dashboard visibility conditions, for code
|
||||
* without a Lit host, such as custom cards and plugins. Conditions core
|
||||
* evaluates are subscribed to; the rest are checked locally. Reports
|
||||
* `unknown` until core replies.
|
||||
*/
|
||||
export const subscribeVisibility = (
|
||||
hass: HomeAssistant,
|
||||
conditions: VisibilityCondition[],
|
||||
onChange: (result: ConditionEvaluation, error?: string) => void,
|
||||
context: ConditionContext = {}
|
||||
): VisibilitySubscription => {
|
||||
// The controller only needs a host to register with and to re-render.
|
||||
const host: ReactiveControllerHost = {
|
||||
addController: () => undefined,
|
||||
removeController: () => undefined,
|
||||
requestUpdate: () => undefined,
|
||||
updateComplete: Promise.resolve(true),
|
||||
};
|
||||
|
||||
let active = true;
|
||||
|
||||
const controller = new ConditionEvaluatorController(host, {
|
||||
resubscribeDelay: 0,
|
||||
onResult: (result, error) => {
|
||||
if (active) {
|
||||
onChange(result, error);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const sanitized = dropInvalidConditions(conditions);
|
||||
const { entity_id: entityId } = context;
|
||||
|
||||
// Core-evaluated conditions never see the context, so fold its entity in
|
||||
// first, as the dashboard mixin does.
|
||||
const validConditions = entityId
|
||||
? sanitized.map((condition) => addEntityToCondition(condition, entityId))
|
||||
: sanitized;
|
||||
const getContext = () => context;
|
||||
|
||||
controller.hostConnected();
|
||||
controller.observe(validConditions, hass, getContext);
|
||||
|
||||
return {
|
||||
update: (newHass) => {
|
||||
if (active) {
|
||||
controller.observe(validConditions, newHass, getContext);
|
||||
}
|
||||
},
|
||||
unsubscribe: () => {
|
||||
active = false;
|
||||
controller.hostDisconnected();
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
import { differenceInMinutes } from "date-fns";
|
||||
import type {
|
||||
DataZoomComponentOption,
|
||||
GridComponentOption,
|
||||
MarkAreaComponentOption,
|
||||
} from "echarts/components";
|
||||
import type { EChartsType } from "echarts/core";
|
||||
@@ -28,7 +27,6 @@ import {
|
||||
eventOptions,
|
||||
property,
|
||||
query,
|
||||
queryAll,
|
||||
state,
|
||||
} from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
@@ -152,9 +150,6 @@ const processSeriesTooltipFormatter = (s: HaECSeriesItem): RawSeriesOption => {
|
||||
|
||||
export type CustomLegendOption = ECOption["legend"] & {
|
||||
type: "custom";
|
||||
// "y-axis" lists the items beside the chart, each one next to its category,
|
||||
// in place of the y-axis labels.
|
||||
position?: "bottom" | "y-axis";
|
||||
data?: {
|
||||
id?: string;
|
||||
secondaryIds?: string[]; // Other dataset IDs that should be controlled by this legend item.
|
||||
@@ -253,9 +248,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
|
||||
@query(".chart") private _chartContainer?: HTMLDivElement;
|
||||
|
||||
@queryAll(".chart-legend button[data-id]")
|
||||
private _legendButtons!: NodeListOf<HTMLElement>;
|
||||
|
||||
@query(".sonification-output")
|
||||
private _sonificationOutput?: HTMLDivElement;
|
||||
|
||||
@@ -327,25 +319,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
},
|
||||
});
|
||||
|
||||
// The axis legend takes width from the chart without resizing the host
|
||||
private _chartResizeController = new ResizeController(this, {
|
||||
target: null,
|
||||
callback: (entries) => {
|
||||
const contentRect = entries[entries.length - 1]?.contentRect;
|
||||
if (
|
||||
this.chart &&
|
||||
contentRect &&
|
||||
(Math.round(contentRect.width) !== this.chart.getWidth() ||
|
||||
Math.round(contentRect.height) !== this.chart.getHeight())
|
||||
) {
|
||||
this._shouldResizeChart = true;
|
||||
this._resizeChartIfNeeded();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
private _focusedLegendButton?: { id: string; toggle: boolean };
|
||||
|
||||
private _loading = false;
|
||||
|
||||
private _reducedMotion = false;
|
||||
@@ -468,7 +441,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
if (!this.isConnected) {
|
||||
return;
|
||||
}
|
||||
this._chartResizeController.observe(this._chartContainer!);
|
||||
// The only measurement taken here: neither observer has reported yet, and a
|
||||
// chart first rendered inside a hidden container has to defer its setup
|
||||
// rather than build against a guessed width.
|
||||
@@ -517,16 +489,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
}
|
||||
|
||||
public willUpdate(changedProps: PropertyValues): void {
|
||||
const focused = this.shadowRoot?.activeElement as HTMLElement | null;
|
||||
this._focusedLegendButton =
|
||||
focused?.dataset.id &&
|
||||
focused.closest(".chart-legend") &&
|
||||
focused.matches(":focus-visible")
|
||||
? {
|
||||
id: focused.dataset.id,
|
||||
toggle: focused.classList.contains("legend-toggle"),
|
||||
}
|
||||
: undefined;
|
||||
if (!this.chart) {
|
||||
return;
|
||||
}
|
||||
@@ -634,7 +596,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
this._resizeChartIfNeeded();
|
||||
}
|
||||
this._renderedLegendFit = this._legendFit.fit;
|
||||
this._restoreLegendFocus();
|
||||
if (changedProps.has("options") || changedProps.has("data")) {
|
||||
// New values keep the widest widths, but other items are fitted afresh
|
||||
const legendItemsKey = JSON.stringify(
|
||||
@@ -649,30 +610,11 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
}
|
||||
}
|
||||
|
||||
// The legend reuses its buttons when items move, which would leave focus on
|
||||
// whichever item now sits where the focused one was
|
||||
private _restoreLegendFocus() {
|
||||
const focused = this._focusedLegendButton;
|
||||
const active = this.shadowRoot?.activeElement as HTMLElement | null;
|
||||
if (!focused || active?.dataset.id === focused.id) {
|
||||
return;
|
||||
}
|
||||
const className = focused.toggle ? "legend-toggle" : "label";
|
||||
Array.from(this._legendButtons)
|
||||
.find(
|
||||
(button) =>
|
||||
button.dataset.id === focused.id &&
|
||||
button.classList.contains(className)
|
||||
)
|
||||
?.focus();
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const sonifiable =
|
||||
!this._sonificationUnavailable &&
|
||||
canSonifyChart(this.data, this._hiddenDatasets);
|
||||
const showZoomSlider = this._showZoomSlider();
|
||||
const axisLegend = this._hasAxisLegend();
|
||||
return html`
|
||||
<div
|
||||
class="container ${classMap({ "has-height": !!this.height })}"
|
||||
@@ -684,14 +626,11 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
})}
|
||||
>
|
||||
<div
|
||||
class="chart-container ${classMap({
|
||||
"has-axis-legend": axisLegend,
|
||||
})}"
|
||||
class="chart-container"
|
||||
style=${styleMap({
|
||||
height: this.height ? undefined : `${this._getDefaultHeight()}px`,
|
||||
})}
|
||||
>
|
||||
${axisLegend ? this._renderAxisLegend() : nothing}
|
||||
<div
|
||||
class="chart ${classMap({
|
||||
"touch-scrub": this._isTouchDevice && this._hasZoomableXAxis(),
|
||||
@@ -717,7 +656,7 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
${showZoomSlider ? this._renderZoomSlider() : nothing}
|
||||
</div>
|
||||
<div class="sonification-output"></div>
|
||||
${axisLegend ? nothing : this._renderLegend()}
|
||||
${this._renderLegend()}
|
||||
<div class="top-controls ${classMap({ small: this.smallControls })}">
|
||||
<slot name="search"></slot>
|
||||
<div
|
||||
@@ -744,22 +683,14 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
`;
|
||||
}
|
||||
|
||||
private _getCustomLegend() {
|
||||
if (!this.options?.legend) {
|
||||
private _getLegendItems() {
|
||||
if (!this.options?.legend || !this.data) {
|
||||
return undefined;
|
||||
}
|
||||
return ensureArray(this.options.legend).find(
|
||||
const legend = ensureArray(this.options.legend).find(
|
||||
(l) => l.show && l.type === "custom"
|
||||
) as CustomLegendOption | undefined;
|
||||
}
|
||||
|
||||
private _hasAxisLegend() {
|
||||
return this._getCustomLegend()?.position === "y-axis";
|
||||
}
|
||||
|
||||
private _getLegendItems() {
|
||||
const legend = this._getCustomLegend();
|
||||
if (!legend || !this.data) {
|
||||
if (!legend) {
|
||||
return undefined;
|
||||
}
|
||||
const datasets = ensureArray(this.data);
|
||||
@@ -776,6 +707,20 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
if (!items) {
|
||||
return nothing;
|
||||
}
|
||||
const datasets = ensureArray(this.data!);
|
||||
// Index datasets by id and name so each legend item is an O(1) lookup
|
||||
// instead of scanning every dataset twice. Charts can have many series.
|
||||
const datasetById = new Map<unknown, (typeof datasets)[number]>();
|
||||
const datasetByName = new Map<unknown, (typeof datasets)[number]>();
|
||||
for (const dataset of datasets) {
|
||||
if (dataset.id !== undefined && !datasetById.has(dataset.id)) {
|
||||
datasetById.set(dataset.id, dataset);
|
||||
}
|
||||
if (dataset.name !== undefined && !datasetByName.has(dataset.name)) {
|
||||
datasetByName.set(dataset.name, dataset);
|
||||
}
|
||||
}
|
||||
|
||||
const fit = this._legendFit.fit ?? items.length;
|
||||
return html`<div
|
||||
class=${classMap({
|
||||
@@ -784,7 +729,73 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
})}
|
||||
>
|
||||
<ul ${this._legendFit.target()}>
|
||||
${this._renderLegendItems(items, fit)}
|
||||
${items.map((item, index) => {
|
||||
let itemStyle: Record<string, any> = {};
|
||||
let value = "";
|
||||
let noLabelClick = false;
|
||||
const name = typeof item === "string" ? item : (item.name ?? "");
|
||||
let id: string;
|
||||
if (typeof item === "string") {
|
||||
id = item;
|
||||
} else {
|
||||
id = item.id ?? name;
|
||||
value = item.value ?? "";
|
||||
itemStyle = item.itemStyle ?? {};
|
||||
noLabelClick = item.noLabelClick ?? false;
|
||||
}
|
||||
const labelClickable = this.clickLabelForMoreInfo && !noLabelClick;
|
||||
const dataset = datasetById.get(id) ?? datasetByName.get(id);
|
||||
itemStyle = {
|
||||
color: dataset?.color as string,
|
||||
...(dataset?.itemStyle as { borderColor?: string }),
|
||||
...itemStyle,
|
||||
};
|
||||
const color = itemStyle?.color as string;
|
||||
return html`<li
|
||||
.id=${id}
|
||||
@pointerdown=${this._legendPointerDown}
|
||||
@pointerup=${this._legendPointerCancel}
|
||||
@pointerleave=${this._legendPointerCancel}
|
||||
@pointercancel=${this._legendPointerCancel}
|
||||
@contextmenu=${this._legendContextMenu}
|
||||
class=${classMap({
|
||||
hidden: this._hiddenDatasets.has(id),
|
||||
overflow: !this.expandLegend && index >= fit,
|
||||
})}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="legend-toggle"
|
||||
data-id=${id}
|
||||
aria-pressed=${!this._hiddenDatasets.has(id)}
|
||||
.title=${this._i18n.localize(
|
||||
"ui.components.history_charts.toggle_visibility"
|
||||
)}
|
||||
@click=${this._toggleDataset}
|
||||
>
|
||||
<ha-svg-icon
|
||||
.path=${
|
||||
this._hiddenDatasets.has(id)
|
||||
? mdiCircleOutline
|
||||
: mdiCheckCircle
|
||||
}
|
||||
style=${styleMap({
|
||||
color: this._hiddenDatasets.has(id) ? undefined : color,
|
||||
})}
|
||||
></ha-svg-icon>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class=${classMap({ label: true, clickable: labelClickable })}
|
||||
data-id=${id}
|
||||
.title=${name}
|
||||
@click=${this._labelClick}
|
||||
>
|
||||
${name}
|
||||
</button>
|
||||
${value ? html`<div class="value">${value}</div>` : nothing}
|
||||
</li>`;
|
||||
})}
|
||||
${
|
||||
items.length
|
||||
? html`<li
|
||||
@@ -818,107 +829,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _renderAxisLegend() {
|
||||
const items = this._getLegendItems() ?? [];
|
||||
const grid = ensureArray(this._getGridOption()!)[0];
|
||||
return html`<div class="chart-legend axis-legend">
|
||||
<ul
|
||||
@pointerover=${this._axisLegendPointerOver}
|
||||
@pointerleave=${this._axisLegendPointerLeave}
|
||||
style=${styleMap({
|
||||
paddingTop: `${grid.top}px`,
|
||||
paddingBottom: `${grid.bottom}px`,
|
||||
})}
|
||||
>
|
||||
${this._renderLegendItems(items, items.length)}
|
||||
</ul>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _renderLegendItems(
|
||||
items: NonNullable<ReturnType<HaChartBase["_getLegendItems"]>>,
|
||||
fit: number
|
||||
) {
|
||||
const datasets = ensureArray(this.data!);
|
||||
// Index datasets by id and name so each legend item is an O(1) lookup
|
||||
// instead of scanning every dataset twice. Charts can have many series.
|
||||
const datasetById = new Map<unknown, (typeof datasets)[number]>();
|
||||
const datasetByName = new Map<unknown, (typeof datasets)[number]>();
|
||||
for (const dataset of datasets) {
|
||||
if (dataset.id !== undefined && !datasetById.has(dataset.id)) {
|
||||
datasetById.set(dataset.id, dataset);
|
||||
}
|
||||
if (dataset.name !== undefined && !datasetByName.has(dataset.name)) {
|
||||
datasetByName.set(dataset.name, dataset);
|
||||
}
|
||||
}
|
||||
return items.map((item, index) => {
|
||||
let itemStyle: Record<string, any> = {};
|
||||
let value = "";
|
||||
let noLabelClick = false;
|
||||
const name = typeof item === "string" ? item : (item.name ?? "");
|
||||
let id: string;
|
||||
if (typeof item === "string") {
|
||||
id = item;
|
||||
} else {
|
||||
id = item.id ?? name;
|
||||
value = item.value ?? "";
|
||||
itemStyle = item.itemStyle ?? {};
|
||||
noLabelClick = item.noLabelClick ?? false;
|
||||
}
|
||||
const labelClickable = this.clickLabelForMoreInfo && !noLabelClick;
|
||||
const dataset = datasetById.get(id) ?? datasetByName.get(id);
|
||||
itemStyle = {
|
||||
color: dataset?.color as string,
|
||||
...(dataset?.itemStyle as { borderColor?: string }),
|
||||
...itemStyle,
|
||||
};
|
||||
const color = itemStyle?.color as string;
|
||||
return html`<li
|
||||
.id=${id}
|
||||
@pointerdown=${this._legendPointerDown}
|
||||
@pointerup=${this._legendPointerCancel}
|
||||
@pointerleave=${this._legendPointerCancel}
|
||||
@pointercancel=${this._legendPointerCancel}
|
||||
@contextmenu=${this._legendContextMenu}
|
||||
class=${classMap({
|
||||
hidden: this._hiddenDatasets.has(id),
|
||||
overflow: !this.expandLegend && index >= fit,
|
||||
})}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="legend-toggle"
|
||||
data-id=${id}
|
||||
aria-pressed=${!this._hiddenDatasets.has(id)}
|
||||
.title=${this._i18n.localize(
|
||||
"ui.components.history_charts.toggle_visibility"
|
||||
)}
|
||||
@click=${this._toggleDataset}
|
||||
>
|
||||
<ha-svg-icon
|
||||
.path=${
|
||||
this._hiddenDatasets.has(id) ? mdiCircleOutline : mdiCheckCircle
|
||||
}
|
||||
style=${styleMap({
|
||||
color: this._hiddenDatasets.has(id) ? undefined : color,
|
||||
})}
|
||||
></ha-svg-icon>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class=${classMap({ label: true, clickable: labelClickable })}
|
||||
data-id=${id}
|
||||
.title=${name}
|
||||
@click=${this._labelClick}
|
||||
>
|
||||
${name}
|
||||
</button>
|
||||
${value ? html`<div class="value">${value}</div>` : nothing}
|
||||
</li>`;
|
||||
});
|
||||
}
|
||||
|
||||
// Chart2Music adds ~45 kB gzipped, so it is only fetched once someone actually
|
||||
// moves keyboard focus into a chart.
|
||||
private async _handleChartFocus() {
|
||||
@@ -1399,28 +1309,14 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
|
||||
private _getGridOption() {
|
||||
const grid = this.options?.grid;
|
||||
const axisLegend = this._hasAxisLegend();
|
||||
if (!axisLegend && (!grid || !this._zoomSliderRoom)) {
|
||||
if (!grid || !this._zoomSliderRoom) {
|
||||
return grid;
|
||||
}
|
||||
const [first, ...rest] = ensureArray(grid ?? {});
|
||||
const result: GridComponentOption = { ...first };
|
||||
if (axisLegend) {
|
||||
// The legend rows are laid out from these, so labels must not move them
|
||||
result.top = this._getGridTop();
|
||||
result.bottom = this._getGridBottom();
|
||||
result.containLabel = false;
|
||||
result.outerBoundsMode = "none";
|
||||
}
|
||||
if (this._zoomSliderRoom) {
|
||||
result.bottom = this._getGridBottom() + this._getZoomSliderSpace();
|
||||
}
|
||||
return [result, ...rest];
|
||||
}
|
||||
|
||||
private _getGridTop() {
|
||||
const top = this.options?.grid && ensureArray(this.options.grid)[0].top;
|
||||
return typeof top === "number" ? top : 0;
|
||||
const [first, ...rest] = ensureArray(grid);
|
||||
return [
|
||||
{ ...first, bottom: this._getGridBottom() + this._getZoomSliderSpace() },
|
||||
...rest,
|
||||
];
|
||||
}
|
||||
|
||||
private _getGridBottom() {
|
||||
@@ -1493,22 +1389,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
} as XAXisOption;
|
||||
});
|
||||
}
|
||||
let yAxis = this.options?.yAxis;
|
||||
if (this._hasAxisLegend()) {
|
||||
const [first, ...rest] = ensureArray(yAxis ?? {});
|
||||
yAxis = [
|
||||
{
|
||||
...first,
|
||||
type: "category",
|
||||
inverse: true,
|
||||
data: this._getLegendItems()?.map((item) =>
|
||||
typeof item === "string" ? item : (item.id ?? item.name)
|
||||
),
|
||||
axisLabel: { ...first.axisLabel, show: false },
|
||||
} as YAXisOption,
|
||||
...rest,
|
||||
];
|
||||
}
|
||||
let legend = this.options?.legend;
|
||||
if (legend) {
|
||||
legend = ensureArray(legend).map((l) =>
|
||||
@@ -1538,7 +1418,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
grid: this._getGridOption(),
|
||||
legend,
|
||||
xAxis,
|
||||
yAxis,
|
||||
};
|
||||
|
||||
if (options.tooltip) {
|
||||
@@ -2139,24 +2018,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
}
|
||||
};
|
||||
|
||||
private _axisLegendPointerOver(ev: PointerEvent) {
|
||||
if (ev.pointerType !== "mouse" || !this.chart) {
|
||||
return;
|
||||
}
|
||||
const id = (ev.target as HTMLElement).closest("li")?.id;
|
||||
if (!id || this._hiddenDatasets.has(id)) {
|
||||
this._hideTooltip();
|
||||
return;
|
||||
}
|
||||
this.chart.dispatchAction({ type: "showTip", seriesIndex: 0, name: id });
|
||||
}
|
||||
|
||||
private _axisLegendPointerLeave(ev: PointerEvent) {
|
||||
if (ev.pointerType === "mouse") {
|
||||
this._hideTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
private _hideTooltip() {
|
||||
this.chart?.dispatchAction({ type: "hideTip" });
|
||||
this.chart?.dispatchAction({
|
||||
@@ -2461,15 +2322,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
.has-height .chart-container {
|
||||
flex: 1;
|
||||
}
|
||||
.chart-container.has-axis-legend {
|
||||
display: flex;
|
||||
/* The chart is not mirrored in RTL, so its legend stays on the left */
|
||||
direction: ltr;
|
||||
}
|
||||
.has-axis-legend .chart {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.chart {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
@@ -2570,29 +2422,6 @@ export class HaChartBase extends MobileAwareMixin(LitElement) {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
}
|
||||
.chart-legend.axis-legend {
|
||||
flex: none;
|
||||
max-width: min(200px, 40%);
|
||||
max-height: none;
|
||||
padding: 0;
|
||||
overflow: visible;
|
||||
direction: var(--direction);
|
||||
}
|
||||
.chart-legend.axis-legend ul {
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
flex-direction: column;
|
||||
flex-wrap: nowrap;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
}
|
||||
.chart-legend.axis-legend li,
|
||||
.chart-legend.axis-legend li:has(.legend-toggle) {
|
||||
flex: 1 1 0;
|
||||
height: auto;
|
||||
min-height: 0;
|
||||
max-width: none;
|
||||
}
|
||||
.chart-legend .hidden {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
|
||||
@@ -1939,6 +1939,10 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
padding-top: var(--code-editor-toolbar-height);
|
||||
}
|
||||
|
||||
:host(.fullscreen) {
|
||||
--code-mirror-min-height: 100%;
|
||||
}
|
||||
|
||||
:host(.fullscreen) .cm-editor {
|
||||
height: 100% !important;
|
||||
max-height: 100% !important;
|
||||
|
||||
@@ -73,6 +73,15 @@ export class HaDropdown extends Dropdown {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
private override async showMenu() {
|
||||
// Flip away from the safe areas instead of opening into them, where the
|
||||
// max-height below would squeeze the menu.
|
||||
const styles = getComputedStyle(this);
|
||||
// @ts-ignore flipPadding is typed as a number, floating-ui accepts sides
|
||||
this.popup.flipPadding = {
|
||||
top: parseFloat(styles.getPropertyValue("--safe-area-inset-top")) || 0,
|
||||
bottom:
|
||||
parseFloat(styles.getPropertyValue("--safe-area-inset-bottom")) || 0,
|
||||
};
|
||||
// @ts-ignore
|
||||
await super.showMenu();
|
||||
const triggerElement = this.getTrigger();
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
getPanelIcon,
|
||||
getPanelIconPath,
|
||||
getPanelTitle,
|
||||
getSelectedPanelUrlPath,
|
||||
} from "../data/panel";
|
||||
import type { PersistentNotification } from "../data/persistent_notification";
|
||||
import { subscribeNotifications } from "../data/persistent_notification";
|
||||
@@ -231,12 +232,36 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const selectedPanel = this.hass.panelUrl;
|
||||
|
||||
// prettier-ignore
|
||||
return html`
|
||||
${this._renderHeader()}
|
||||
${this._renderAllPanels(selectedPanel)}`;
|
||||
${this._renderAllPanels()}`;
|
||||
}
|
||||
|
||||
private _computeSidebarPanels(): [PanelInfo[], PanelInfo[]] | undefined {
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
return undefined;
|
||||
}
|
||||
return computePanels(
|
||||
this.hass.panels,
|
||||
getDefaultPanelUrlPath(this.hass),
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
}
|
||||
|
||||
private _computeSelectedPanel(
|
||||
sidebarPanels: [PanelInfo[], PanelInfo[]] | undefined,
|
||||
route: Route | undefined
|
||||
): string {
|
||||
if (!route) {
|
||||
return this.hass.panelUrl;
|
||||
}
|
||||
const urlPaths = (sidebarPanels ?? [[], []])
|
||||
.flat()
|
||||
.map((panel) => panel.url_path);
|
||||
return getSelectedPanelUrlPath(urlPaths, route.path);
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
@@ -254,7 +279,20 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (!this.hass || !changedProps.has("hass")) {
|
||||
if (!this.hass) {
|
||||
return false;
|
||||
}
|
||||
if (changedProps.has("route")) {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const oldRoute = changedProps.get("route") as Route | undefined;
|
||||
if (
|
||||
this._computeSelectedPanel(sidebarPanels, oldRoute) !==
|
||||
this._computeSelectedPanel(sidebarPanels, this.route)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!changedProps.has("hass")) {
|
||||
return false;
|
||||
}
|
||||
const oldHass = changedProps.get("hass") as HomeAssistant;
|
||||
@@ -355,7 +393,9 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _renderAllPanels(selectedPanel: string) {
|
||||
private _renderAllPanels() {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const selectedPanel = this._computeSelectedPanel(sidebarPanels, this.route);
|
||||
const renderList = (content, cls: string, scrollable: boolean) =>
|
||||
html`<ha-list-nav
|
||||
class=${classMap({
|
||||
@@ -365,7 +405,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
>${content}</ha-list-nav
|
||||
>`;
|
||||
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
if (!sidebarPanels) {
|
||||
return html`<div class="panels-list">
|
||||
<div class="wrapper">
|
||||
${renderList(
|
||||
@@ -390,15 +430,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||
|
||||
const [beforeSpacer, afterSpacer] = computePanels(
|
||||
this.hass.panels,
|
||||
defaultPanel,
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
const [beforeSpacer, afterSpacer] = sidebarPanels;
|
||||
|
||||
// prettier-ignore
|
||||
return html`<div class="panels-list">
|
||||
|
||||
@@ -196,6 +196,21 @@ export const getPanelIconPath = (panel: PanelInfo): string | undefined => {
|
||||
|
||||
export const FIXED_PANELS = [PROFILE_PANEL, "config", NOT_FOUND_PANEL];
|
||||
|
||||
// A panel's url_path can span several segments (e.g. "config/logs"), so the
|
||||
// most specific url_path matching the path wins over its first segment.
|
||||
export const getSelectedPanelUrlPath = (
|
||||
urlPaths: string[],
|
||||
path: string
|
||||
): string =>
|
||||
urlPaths.reduce(
|
||||
(selected, urlPath) =>
|
||||
urlPath.length > selected.length &&
|
||||
(path === `/${urlPath}` || path.startsWith(`/${urlPath}/`))
|
||||
? urlPath
|
||||
: selected,
|
||||
path.split("/")[1] ?? ""
|
||||
);
|
||||
|
||||
export interface PanelMutableParams {
|
||||
title?: string | null;
|
||||
icon?: string | null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ContextType } from "@lit/context";
|
||||
import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { ERR_CONNECTION_LOST } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
@@ -456,6 +457,11 @@ class MoreInfoUpdate extends LitElement {
|
||||
false
|
||||
);
|
||||
} catch (err: any) {
|
||||
// The update keeps running when the connection drops during a long install.
|
||||
if (err?.error?.code === ERR_CONNECTION_LOST) {
|
||||
return;
|
||||
}
|
||||
|
||||
const message = await this._localizeInstallError(err);
|
||||
|
||||
if (this._isShown()) {
|
||||
|
||||
@@ -620,15 +620,14 @@ class MoreInfoWeather extends LitElement {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: var(--ha-space-6);
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: absolute;
|
||||
position: relative;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
|
||||
@@ -2,4 +2,10 @@ import "@webcomponents/scoped-custom-element-registry/scoped-custom-element-regi
|
||||
import "../resources/scoped-registry-ready";
|
||||
import "../layouts/home-assistant";
|
||||
|
||||
// Custom cards and plugins can reach the helpers on any page, not only once a
|
||||
// dashboard has loaded.
|
||||
Object.assign(window, {
|
||||
loadCardHelpers: () => import("../panels/lovelace/custom-card-helpers"),
|
||||
});
|
||||
|
||||
import("../resources/append-ha-style");
|
||||
@@ -93,13 +93,13 @@ export class CloudRemotePref extends LitElement {
|
||||
<ha-card
|
||||
outlined
|
||||
header=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.card_title"
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
)}
|
||||
>
|
||||
<div class="header-actions">
|
||||
<ha-switch
|
||||
.accessibleLabel=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.card_title"
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
)}
|
||||
.checked=${remote_enabled}
|
||||
@change=${this._toggleChanged}
|
||||
|
||||
@@ -104,7 +104,7 @@ export class CloudWebhooks extends LitElement {
|
||||
<div class="card-actions">
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
href="https://www.nabucasa.com/config/webhooks"
|
||||
href="https://www.nabucasa.com/config/webhooks/"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
|
||||
@@ -514,8 +514,16 @@ class AddIntegrationDialog extends LitElement {
|
||||
return [...integrations]
|
||||
.filter((item) => !brand || item.domain === brand)
|
||||
.sort(byName)
|
||||
.flatMap((item) => this._brandRows(item))
|
||||
.filter((row) => !brand || !row.is_header);
|
||||
.flatMap((item) =>
|
||||
this._brandRows(item)
|
||||
.filter((row) => !row.is_header)
|
||||
// The brand on the second line, so its entries read as a group
|
||||
.map((row) =>
|
||||
brand || !this._isBrand(item)
|
||||
? row
|
||||
: { ...row, description: item.name }
|
||||
)
|
||||
);
|
||||
}
|
||||
// A brand shows its integrations here, not itself, like the website
|
||||
if (category) {
|
||||
@@ -1207,17 +1215,11 @@ class AddIntegrationDialog extends LitElement {
|
||||
})}
|
||||
>
|
||||
${
|
||||
!this._stickyBrand
|
||||
? nothing
|
||||
: this._filter
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: html`<ha-integration-list-title
|
||||
class="sticky raised"
|
||||
>
|
||||
${this._stickyBrand}
|
||||
</ha-integration-list-title>`
|
||||
this._stickyBrand
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: nothing
|
||||
}
|
||||
<ha-list-virtualized
|
||||
.rows=${this._filter ? rows : this._withEndSpace(rows)}
|
||||
@@ -1771,7 +1773,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the brand
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the section title
|
||||
@eventOptions({ passive: true })
|
||||
private _visibilityChanged(ev: HASSDomEvent<HaListVisibilityChangedDetail>) {
|
||||
const rows = this._getRows();
|
||||
@@ -1794,11 +1796,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
return html`<div style="height: var(--ha-space-2)"></div>`;
|
||||
}
|
||||
if (integration.is_header) {
|
||||
return this._filter
|
||||
? html`<ha-section-title>${integration.name}</ha-section-title>`
|
||||
: html`<ha-integration-list-title>
|
||||
${integration.name}
|
||||
</ha-integration-list-title>`;
|
||||
return html`<ha-section-title>${integration.name}</ha-section-title>`;
|
||||
}
|
||||
return html`
|
||||
<ha-integration-list-item
|
||||
|
||||
@@ -26,6 +26,7 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import { formatListWithAnds } from "../../../common/string/format-list";
|
||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||
import "../../../components/ha-dropdown";
|
||||
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
|
||||
@@ -95,6 +96,9 @@ export class HaConfigEntryRow extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public data!: ConfigEntryData;
|
||||
|
||||
/** The loaded integrations that lose this integration with this entry. */
|
||||
@property({ attribute: false }) public dependents?: IntegrationManifest[];
|
||||
|
||||
@state() private _expanded = true;
|
||||
|
||||
@state() private _devicesExpanded = true;
|
||||
@@ -812,14 +816,33 @@ export class HaConfigEntryRow extends LitElement {
|
||||
const applicationCredentialsId =
|
||||
await this._applicationCredentialForRemove(entryId);
|
||||
|
||||
const text = this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
);
|
||||
const confirmed = await showConfirmationDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_title",
|
||||
{ title: this.data.entry.title }
|
||||
),
|
||||
text: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
),
|
||||
text: this.dependents?.length
|
||||
? html`${text}<br /><br />${this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_dependents",
|
||||
{
|
||||
count: this.dependents.length,
|
||||
integrations: formatListWithAnds(
|
||||
this.hass.locale,
|
||||
this.dependents.map((manifest) =>
|
||||
domainToName(this.hass.localize, manifest.domain, manifest)
|
||||
)
|
||||
),
|
||||
name: domainToName(
|
||||
this.hass.localize,
|
||||
this.data.entry.domain,
|
||||
this.manifest
|
||||
),
|
||||
}
|
||||
)}`
|
||||
: text,
|
||||
confirmText: this.hass!.localize("ui.common.delete"),
|
||||
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||
destructive: true,
|
||||
|
||||
@@ -21,7 +21,7 @@ import memoizeOne from "memoize-one";
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { QueryParamsController } from "../../../common/controllers/query-params-controller";
|
||||
import { ContextSubscriptionController } from "../../../common/decorators/consume";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import type { HASSDomTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { computeDeviceNameDisplay } from "../../../common/entity/compute_device_name";
|
||||
import {
|
||||
@@ -176,9 +176,9 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
@state() private _manifest?: IntegrationManifest;
|
||||
|
||||
/** The manifests of all loaded integrations, to find the dependents. */
|
||||
@state() private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
private _manifestsConsumer?: ContextSubscriptionController<DomainManifestLookup>;
|
||||
@consume({ context: manifestsContext, subscribe: true })
|
||||
@state()
|
||||
private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
@state() private _extraConfigEntries?: ConfigEntry[];
|
||||
|
||||
@@ -432,17 +432,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
this.domain
|
||||
);
|
||||
|
||||
const dependents = this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
);
|
||||
// Without the dependents, a dependency looks like a YAML integration.
|
||||
const dependents =
|
||||
this._manifest && !this._manifest.config_flow
|
||||
? this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
)
|
||||
: [];
|
||||
const showDependents = normalEntries.length === 0 && dependents.length > 0;
|
||||
const dependencyOnly =
|
||||
normalEntries.length === 0 &&
|
||||
dependents.length > 0 &&
|
||||
!this._manifest?.config_flow;
|
||||
// Deleting the last entry in use leaves the dependents without it.
|
||||
const entriesInUse = configEntries.filter(
|
||||
(entry) => entry.source !== "ignore" && !entry.disabled_by
|
||||
);
|
||||
const lastEntryId =
|
||||
entriesInUse.length === 1 ? entriesInUse[0].entry_id : undefined;
|
||||
// Hold back the YAML texts and "Add entry" until the manifest and the
|
||||
// dependents are known. Entries do not wait, so a failed request cannot
|
||||
// hide them.
|
||||
@@ -461,7 +467,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
|
||||
const showAddEntry =
|
||||
this._manifest?.integration_type !== "hardware" &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
(!this._manifest?.single_config_entry ||
|
||||
@@ -653,7 +659,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
${
|
||||
normalEntries.length === 0 &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
this._manifest &&
|
||||
@@ -1010,6 +1016,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1018,19 +1029,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents ||
|
||||
dependencyOnly ||
|
||||
dependentsLoading ||
|
||||
(setUpInPanel && normalEntries.length === 0)
|
||||
? nothing
|
||||
@@ -1077,6 +1076,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1084,26 +1088,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
</div>`
|
||||
}
|
||||
${
|
||||
dependents.length
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
</hass-subpage>
|
||||
`;
|
||||
}
|
||||
|
||||
// Only an integration without a config flow needs the loaded manifests, so
|
||||
// other integration pages do not make the context fetch them.
|
||||
private _watchLoadedManifests(): void {
|
||||
if (this._manifestsConsumer) {
|
||||
return;
|
||||
}
|
||||
this._manifestsConsumer = new ContextSubscriptionController(
|
||||
this,
|
||||
manifestsContext,
|
||||
(manifests) => {
|
||||
this._loadedManifests = manifests;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private _getDependents = memoizeOne(
|
||||
(
|
||||
domain: string,
|
||||
@@ -1199,9 +1200,6 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
this._manifest = await fetchIntegrationManifest(this.hass, this.domain);
|
||||
if (!this._manifest.config_flow) {
|
||||
this._watchLoadedManifests();
|
||||
}
|
||||
if (
|
||||
this._manifest.integration_type &&
|
||||
!["device", "hub", "service"].includes(this._manifest.integration_type)
|
||||
|
||||
@@ -14,6 +14,7 @@ import { consume } from "../../../../common/decorators/consume";
|
||||
import { formatNumberWithUnit } from "../../../../common/number/format_number";
|
||||
import "../../../../components/chart/ha-chart-base";
|
||||
import "../../../../components/chart/ha-chart-tooltip-marker";
|
||||
import { wrapLitTooltipFormatter } from "../../../../components/chart/lit-tooltip-formatter";
|
||||
import {
|
||||
formattersContext,
|
||||
internationalizationContext,
|
||||
@@ -49,6 +50,7 @@ import type { HaECOption } from "../../../../resources/echarts/echarts";
|
||||
import "../../../../components/ha-card";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { measureTextWidth } from "../../../../util/text";
|
||||
import "../../../../components/ha-icon-button";
|
||||
import { storage } from "../../../../common/decorators/storage";
|
||||
import { getEnergyColor } from "./common/color";
|
||||
@@ -196,9 +198,9 @@ export class HuiEnergyDevicesGraphCard
|
||||
<ha-chart-base
|
||||
.data=${this._chartData}
|
||||
.options=${this._createOptions(
|
||||
this._chartData,
|
||||
this._chartType,
|
||||
this._legendData,
|
||||
this._hiddenStats
|
||||
this._legendData
|
||||
)}
|
||||
.height=${`${Math.max(modes.includes("pie") ? 300 : 100, (this._legendData?.length || 0) * 28 + 50)}px`}
|
||||
.sonificationLabelFormatter=${this._sonificationLabel}
|
||||
@@ -250,61 +252,97 @@ export class HuiEnergyDevicesGraphCard
|
||||
<div style="direction:ltr; display: inline;">${value}</div>`;
|
||||
};
|
||||
|
||||
private _renderLabelTooltip = wrapLitTooltipFormatter(
|
||||
(params: { value: string }) => {
|
||||
const series = this._chartData[0];
|
||||
const item = (series?.data as any[] | undefined)?.find(
|
||||
(d) => d.id === params.value
|
||||
);
|
||||
return item
|
||||
? this._renderTooltip({
|
||||
name: item.name,
|
||||
value: item.value,
|
||||
color: item.itemStyle.color,
|
||||
seriesName: series.name,
|
||||
})
|
||||
: nothing;
|
||||
}
|
||||
);
|
||||
|
||||
private _createOptions = memoizeOne(
|
||||
(
|
||||
data: (BarSeriesOption | PieSeriesOption)[],
|
||||
chartType: "bar" | "pie",
|
||||
legendData: typeof this._legendData,
|
||||
hiddenStats: string[]
|
||||
legendData: typeof this._legendData
|
||||
): HaECOption => {
|
||||
const selected = Object.fromEntries(hiddenStats.map((id) => [id, false]));
|
||||
if (chartType === "bar") {
|
||||
const legend: CustomLegendOption = {
|
||||
type: "custom",
|
||||
show: true,
|
||||
position: "y-axis",
|
||||
data: [
|
||||
...legendData.filter((d) => !hiddenStats.includes(d.id!)),
|
||||
...legendData.filter((d) => hiddenStats.includes(d.id!)),
|
||||
].map(({ value: _value, ...item }) => item),
|
||||
selected,
|
||||
};
|
||||
return {
|
||||
grid: {
|
||||
top: 0,
|
||||
bottom: 24,
|
||||
left: 8,
|
||||
right: 40,
|
||||
},
|
||||
tooltip: {
|
||||
show: true,
|
||||
formatter: this._renderTooltip,
|
||||
},
|
||||
xAxis: {
|
||||
show: true,
|
||||
type: "value",
|
||||
name: "kWh",
|
||||
axisPointer: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
yAxis: { show: true, type: "category" },
|
||||
legend,
|
||||
};
|
||||
}
|
||||
return {
|
||||
const options: HaECOption = {
|
||||
grid: {
|
||||
top: 5,
|
||||
left: 5,
|
||||
right: 40,
|
||||
bottom: 0,
|
||||
containLabel: true,
|
||||
},
|
||||
tooltip: {
|
||||
show: true,
|
||||
formatter: this._renderTooltip,
|
||||
},
|
||||
xAxis: { show: false },
|
||||
yAxis: { show: false },
|
||||
legend: {
|
||||
legend: { type: "custom", show: false },
|
||||
};
|
||||
if (chartType === "bar") {
|
||||
options.xAxis = {
|
||||
show: true,
|
||||
type: "value",
|
||||
name: "kWh",
|
||||
axisPointer: {
|
||||
show: false,
|
||||
},
|
||||
};
|
||||
options.yAxis = {
|
||||
show: true,
|
||||
type: "category",
|
||||
inverse: true,
|
||||
triggerEvent: true,
|
||||
// ECharts types only list `show`, but the label tooltip takes the
|
||||
// formatter too
|
||||
tooltip: {
|
||||
show: true,
|
||||
formatter: this._renderLabelTooltip,
|
||||
} as { show: boolean },
|
||||
// take order from data
|
||||
data: data[0]?.data?.map((d: any) => d.name),
|
||||
axisLabel: {
|
||||
formatter: this._getDeviceName.bind(this),
|
||||
overflow: "truncate",
|
||||
fontSize: 12,
|
||||
margin: 5,
|
||||
width: Math.min(
|
||||
this._isMobileSize ? 100 : 200,
|
||||
Math.max(
|
||||
...(data[0]?.data?.map(
|
||||
(d: any) =>
|
||||
measureTextWidth(this._getDeviceName(d.name), 12) + 5
|
||||
) || [])
|
||||
)
|
||||
),
|
||||
},
|
||||
};
|
||||
} else {
|
||||
options.legend = {
|
||||
type: "custom",
|
||||
show: true,
|
||||
data: legendData,
|
||||
selected,
|
||||
},
|
||||
};
|
||||
selected: legendData
|
||||
.filter((d) => d.id && this._hiddenStats.includes(d.id))
|
||||
.reduce((acc, d) => {
|
||||
acc[d.id!] = false;
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
return options;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -619,6 +657,14 @@ export class HuiEnergyDevicesGraphCard
|
||||
|
||||
private _handleChartClick(e: CustomEvent<ECElementEvent>): void {
|
||||
if (
|
||||
e.detail.targetType === "axisLabel" &&
|
||||
e.detail.value &&
|
||||
!isExternalStatistic(e.detail.value as string)
|
||||
) {
|
||||
fireEvent(this, "hass-more-info", {
|
||||
entityId: e.detail.value as string,
|
||||
});
|
||||
} else if (
|
||||
e.detail.seriesType === "pie" &&
|
||||
e.detail.event?.target?.type === "tspan" // label
|
||||
) {
|
||||
|
||||
@@ -820,15 +820,14 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: 24px;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: absolute;
|
||||
position: relative;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
@@ -1025,12 +1024,6 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
||||
font-size: var(--ha-font-size-xl);
|
||||
}
|
||||
|
||||
[class*="narrow"] .temp-attribute .temp {
|
||||
margin-right: 16px;
|
||||
margin-inline-end: 16px;
|
||||
margin-inline-start: initial;
|
||||
}
|
||||
|
||||
[class*="narrow"] .temp span {
|
||||
top: 1px;
|
||||
font-size: var(--ha-font-size-l);
|
||||
|
||||
@@ -9,6 +9,8 @@ export {
|
||||
showPromptDialog,
|
||||
} from "../../dialogs/generic/show-dialog-box";
|
||||
export { importMoreInfoControl } from "../../dialogs/more-info/state_more_info_control";
|
||||
|
||||
export { subscribeVisibility } from "../../common/condition/subscribe-visibility";
|
||||
export { createBadgeElement } from "./create-element/create-badge-element";
|
||||
export { createCardElement } from "./create-element/create-card-element";
|
||||
export { createHeaderFooterElement } from "./create-element/create-header-footer-element";
|
||||
|
||||
@@ -8,6 +8,7 @@ import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { ctrlOrCmdLabel } from "../../../../common/keyboard/ctrl-or-cmd";
|
||||
@@ -75,6 +76,8 @@ export class HuiDialogEditBadge
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _badgeConfig?: LovelaceBadgeConfig;
|
||||
|
||||
@state() private _saving = false;
|
||||
@@ -99,6 +102,7 @@ export class HuiDialogEditBadge
|
||||
this._badgeConfig = params.badgeConfig;
|
||||
|
||||
this.large = false;
|
||||
this._animateWidth = false;
|
||||
if (this._badgeConfig && !Object.isFrozen(this._badgeConfig)) {
|
||||
this._badgeConfig = deepFreeze(this._badgeConfig);
|
||||
}
|
||||
@@ -202,7 +206,10 @@ export class HuiDialogEditBadge
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -345,11 +352,21 @@ export class HuiDialogEditBadge
|
||||
|
||||
private _handleGUIModeChanged(ev: HASSDomEvent<GUIModeChangedEvent>): void {
|
||||
ev.stopPropagation();
|
||||
// Fired again on every error while staying in the same mode
|
||||
if (ev.detail.guiMode !== this._GUImode) {
|
||||
if (ev.detail.guiMode) {
|
||||
this.large = this._largeBeforeCodeEditor;
|
||||
} else {
|
||||
this._largeBeforeCodeEditor = this.large;
|
||||
this.large = true;
|
||||
}
|
||||
}
|
||||
this._GUImode = ev.detail.guiMode;
|
||||
this._guiModeAvailable = ev.detail.guiModeAvailable;
|
||||
}
|
||||
|
||||
private _toggleMode(): void {
|
||||
this._animateWidth = true;
|
||||
withViewTransition(() => {
|
||||
this._badgeEditorEl?.toggleMode();
|
||||
});
|
||||
@@ -513,6 +530,17 @@ export class HuiDialogEditBadge
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
|
||||
@@ -8,6 +8,7 @@ import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
@@ -83,6 +84,8 @@ export class HuiDialogEditCard
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _cardConfig?: LovelaceCardConfig;
|
||||
|
||||
@state() private _sectionConfig?: LovelaceSectionConfig;
|
||||
@@ -111,6 +114,7 @@ export class HuiDialogEditCard
|
||||
this._cardConfig = params.cardConfig;
|
||||
|
||||
this.large = false;
|
||||
this._animateWidth = false;
|
||||
if (this._cardConfig && !Object.isFrozen(this._cardConfig)) {
|
||||
this._cardConfig = deepFreeze(this._cardConfig);
|
||||
}
|
||||
@@ -214,7 +218,10 @@ export class HuiDialogEditCard
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -371,11 +378,21 @@ export class HuiDialogEditCard
|
||||
|
||||
private _handleGUIModeChanged(ev: HASSDomEvent<GUIModeChangedEvent>): void {
|
||||
ev.stopPropagation();
|
||||
// Fired again on every error while staying in the same mode
|
||||
if (ev.detail.guiMode !== this._GUImode) {
|
||||
if (ev.detail.guiMode) {
|
||||
this.large = this._largeBeforeCodeEditor;
|
||||
} else {
|
||||
this._largeBeforeCodeEditor = this.large;
|
||||
this.large = true;
|
||||
}
|
||||
}
|
||||
this._GUImode = ev.detail.guiMode;
|
||||
this._guiModeAvailable = ev.detail.guiModeAvailable;
|
||||
}
|
||||
|
||||
private _toggleMode(): void {
|
||||
this._animateWidth = true;
|
||||
withViewTransition(() => {
|
||||
this._cardEditorEl?.toggleMode();
|
||||
});
|
||||
@@ -595,6 +612,17 @@ export class HuiDialogEditCard
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
|
||||
@@ -264,8 +264,11 @@ export class HuiDialogEditSection
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
width="large"
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
style=${styleMap({ "--preview-column-span": previewColumnSpan })}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@@ -529,6 +532,7 @@ export class HuiDialogEditSection
|
||||
|
||||
private async _toggleMode(): Promise<void> {
|
||||
if (this._yamlMode && this._yamlError) return;
|
||||
this._animateWidth = true;
|
||||
await withViewTransition(() => {
|
||||
this._yamlMode = !this._yamlMode;
|
||||
});
|
||||
@@ -750,6 +754,17 @@ export class HuiDialogEditSection
|
||||
);
|
||||
}
|
||||
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
@@ -836,10 +851,11 @@ export class HuiDialogEditSection
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog {
|
||||
--editor-column-width: 520px;
|
||||
/* Plus the paddings of the preview and the dialog */
|
||||
/* Plus the paddings of the preview */
|
||||
--preview-column-total-width: calc(var(--preview-width) + 28px);
|
||||
--ha-dialog-width-lg: calc(
|
||||
var(--editor-column-width) + var(--preview-width) + 28px + 2 *
|
||||
var(--dialog-content-padding)
|
||||
var(--editor-column-width) + var(--preview-column-total-width) +
|
||||
2 * var(--dialog-content-padding)
|
||||
);
|
||||
}
|
||||
.content {
|
||||
@@ -854,6 +870,13 @@ export class HuiDialogEditSection
|
||||
.content > .element-preview {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
ha-dialog.yaml-mode .content > .element-editor {
|
||||
flex: 1 0 var(--editor-column-width);
|
||||
}
|
||||
ha-dialog.yaml-mode .content > .element-preview {
|
||||
box-sizing: border-box;
|
||||
flex: 0 1 var(--preview-column-total-width);
|
||||
}
|
||||
.content > .element-editor,
|
||||
.content > .element-preview {
|
||||
min-width: 0;
|
||||
|
||||
@@ -90,6 +90,8 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
get _type(): string {
|
||||
return getViewType(this._config);
|
||||
}
|
||||
@@ -136,6 +138,7 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
this._params = undefined;
|
||||
this._config = {};
|
||||
this._yamlMode = false;
|
||||
this._animateWidth = false;
|
||||
this._currTab = TABS[0];
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
@@ -210,10 +213,12 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${this._viewConfigTitle}
|
||||
width="large"
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@closed=${this._dialogClosed}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
>
|
||||
@@ -365,7 +370,13 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
}
|
||||
}
|
||||
|
||||
// The code editor's fullscreen changes the height at once, so the width must not lag behind
|
||||
private _stopWidthAnimation() {
|
||||
this._animateWidth = false;
|
||||
}
|
||||
|
||||
private async _toggleMode() {
|
||||
this._animateWidth = true;
|
||||
this._yamlMode = !this._yamlMode;
|
||||
if (this._yamlMode) {
|
||||
await this.updateComplete;
|
||||
@@ -680,6 +691,29 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
ha-dialog.yaml-mode {
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* 80px - margin of the dialog
|
||||
137px - header and footer */
|
||||
--code-mirror-max-height: calc(100vh - 217px);
|
||||
}
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
max-width var(--ha-animation-duration-normal) ease-out;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: inherit;
|
||||
|
||||
@@ -305,6 +305,11 @@ export const haTheme = EditorView.theme({
|
||||
|
||||
".cm-scroller": { outline: "none" },
|
||||
|
||||
// On these instead of the editor, so that the gutter grows along
|
||||
".cm-content, .cm-gutter": {
|
||||
minHeight: "var(--code-mirror-min-height, 100%)",
|
||||
},
|
||||
|
||||
".cm-content": {
|
||||
caretColor: "var(--secondary-text-color)",
|
||||
paddingTop: "16px",
|
||||
|
||||
@@ -7616,7 +7616,6 @@
|
||||
},
|
||||
"remote": {
|
||||
"title": "Remote access",
|
||||
"card_title": "Remote connection",
|
||||
"connected": "Connected",
|
||||
"not_connected": "Not connected",
|
||||
"reconnecting": "Not connected. Trying to reconnect.",
|
||||
@@ -8266,6 +8265,7 @@
|
||||
"delete": "Delete",
|
||||
"delete_confirm_title": "Delete {title}?",
|
||||
"delete_confirm_text": "Its devices and entities will be permanently deleted.",
|
||||
"delete_confirm_dependents": "{integrations} {count, plural,\n one {depends on {name} and may stop working.}\n other {depend on {name} and may stop working.}\n}",
|
||||
"enable_debug_logging": "Enable debug logging",
|
||||
"reconfigure": "Reconfigure",
|
||||
"reload": "Reload",
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { subscribeVisibility } from "../../../src/common/condition/subscribe-visibility";
|
||||
import type { VisibilityCondition } from "../../../src/panels/lovelace/common/validate-condition";
|
||||
import type { HomeAssistant } from "../../../src/types";
|
||||
|
||||
interface CapturedSubscription {
|
||||
push: (message: { result?: boolean }) => void;
|
||||
unsub: ReturnType<typeof vi.fn>;
|
||||
condition: unknown;
|
||||
}
|
||||
|
||||
let subs: CapturedSubscription[];
|
||||
|
||||
const tick = () =>
|
||||
new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, 10);
|
||||
});
|
||||
|
||||
const createHass = (userId = "user1"): HomeAssistant =>
|
||||
({
|
||||
connection: {
|
||||
subscribeMessage: vi.fn(
|
||||
(
|
||||
onChange: CapturedSubscription["push"],
|
||||
msg: { condition: unknown }
|
||||
) => {
|
||||
const unsub = vi.fn();
|
||||
|
||||
subs.push({ push: onChange, unsub, condition: msg.condition });
|
||||
|
||||
return Promise.resolve(unsub);
|
||||
}
|
||||
),
|
||||
},
|
||||
states: {},
|
||||
user: { id: userId },
|
||||
locale: { time_zone: "local" },
|
||||
config: { time_zone: "America/New_York" },
|
||||
}) as unknown as HomeAssistant;
|
||||
|
||||
describe("subscribeVisibility", () => {
|
||||
beforeEach(() => {
|
||||
subs = [];
|
||||
});
|
||||
|
||||
it("checks client conditions again with each hass passed to update", async () => {
|
||||
const onChange = vi.fn();
|
||||
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "user", users: ["user1"] },
|
||||
];
|
||||
|
||||
const subscription = subscribeVisibility(
|
||||
createHass("user1"),
|
||||
conditions,
|
||||
onChange
|
||||
);
|
||||
|
||||
await tick();
|
||||
expect(onChange).toHaveBeenLastCalledWith("visible", undefined);
|
||||
|
||||
subscription.update(createHass("user2"));
|
||||
expect(onChange).toHaveBeenLastCalledWith("hidden", undefined);
|
||||
});
|
||||
|
||||
it("closes core subscriptions and stops reporting after unsubscribe", async () => {
|
||||
const onChange = vi.fn();
|
||||
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "state", entity: "light.kitchen", state: "on" },
|
||||
];
|
||||
|
||||
const subscription = subscribeVisibility(
|
||||
createHass(),
|
||||
conditions,
|
||||
onChange
|
||||
);
|
||||
|
||||
await tick();
|
||||
expect(subs).toHaveLength(1);
|
||||
|
||||
subs[0].push({ result: true });
|
||||
expect(onChange).toHaveBeenLastCalledWith("visible", undefined);
|
||||
onChange.mockClear();
|
||||
|
||||
subscription.unsubscribe();
|
||||
await tick();
|
||||
expect(subs[0].unsub).toHaveBeenCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sends the context entity to core for conditions without one", async () => {
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "state", state: "on" },
|
||||
];
|
||||
|
||||
subscribeVisibility(createHass(), conditions, vi.fn(), {
|
||||
entity_id: "light.kitchen",
|
||||
});
|
||||
|
||||
await tick();
|
||||
expect(subs).toHaveLength(1);
|
||||
expect(subs[0].condition).toEqual({
|
||||
condition: "state",
|
||||
entity_id: "light.kitchen",
|
||||
state: "on",
|
||||
});
|
||||
});
|
||||
});
|
||||
+44
-1
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getConfigSubpageTitle } from "../../src/data/panel";
|
||||
import {
|
||||
getConfigSubpageTitle,
|
||||
getSelectedPanelUrlPath,
|
||||
} from "../../src/data/panel";
|
||||
import type { PageNavigation } from "../../src/layouts/hass-tabs-subpage";
|
||||
import type { HomeAssistant } from "../../src/types";
|
||||
|
||||
@@ -83,3 +86,43 @@ describe("getConfigSubpageTitle", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSelectedPanelUrlPath", () => {
|
||||
const urlPaths = ["lovelace", "history", "config/logs", "config/logs/raw"];
|
||||
|
||||
it("falls back to the first path segment", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/automation")).toBe(
|
||||
"config"
|
||||
);
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/profile/general")).toBe(
|
||||
"profile"
|
||||
);
|
||||
});
|
||||
|
||||
it("selects a panel whose url_path has several segments", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs")).toBe(
|
||||
"config/logs"
|
||||
);
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs/details")).toBe(
|
||||
"config/logs"
|
||||
);
|
||||
});
|
||||
|
||||
it("prefers the most specific url_path", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs/raw")).toBe(
|
||||
"config/logs/raw"
|
||||
);
|
||||
});
|
||||
|
||||
it("only matches whole segments", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logsfoo")).toBe("config");
|
||||
});
|
||||
|
||||
it("keeps matching single segment panels on their subpaths", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/lovelace/0")).toBe("lovelace");
|
||||
});
|
||||
|
||||
it("returns an empty url_path for the root path", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/")).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user