mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-03 10:09:48 +00:00
Compare commits
3
Commits
20261125.3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088640642c | ||
|
|
0819c80044 | ||
|
|
bb0c3bcd80 |
No files matched your search
@@ -508,12 +508,8 @@ const createRspackConfig = ({
|
||||
"@formatjs/intl-locale/should-polyfill.js",
|
||||
"@formatjs/intl-locale/polyfill-force":
|
||||
"@formatjs/intl-locale/polyfill-force.js",
|
||||
"@formatjs/intl-numberformat/should-polyfill":
|
||||
"@formatjs/intl-numberformat/should-polyfill.js",
|
||||
"@formatjs/intl-numberformat/polyfill-force":
|
||||
"@formatjs/intl-numberformat/polyfill-force.js",
|
||||
"@formatjs/intl-pluralrules/should-polyfill":
|
||||
"@formatjs/intl-pluralrules/should-polyfill.js",
|
||||
"@formatjs/intl-pluralrules/polyfill-force":
|
||||
"@formatjs/intl-pluralrules/polyfill-force.js",
|
||||
"@formatjs/intl-relativetimeformat/should-polyfill":
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "home-assistant-frontend"
|
||||
version = "20261125.3"
|
||||
version = "20261125.4"
|
||||
license = "Apache-2.0"
|
||||
license-files = ["LICENSE*"]
|
||||
description = "The Home Assistant frontend"
|
||||
|
||||
@@ -244,7 +244,7 @@ export class ConditionEvaluatorController implements ReactiveController {
|
||||
return;
|
||||
}
|
||||
if (message.error !== undefined) {
|
||||
this._serverResults[subtree.id] = false;
|
||||
this._serverResults[subtree.id] = undefined;
|
||||
this._subtreeErrors[subtree.id] =
|
||||
typeof message.error === "string"
|
||||
? message.error
|
||||
@@ -265,7 +265,7 @@ export class ConditionEvaluatorController implements ReactiveController {
|
||||
if (generation !== this._generation) {
|
||||
return;
|
||||
}
|
||||
this._serverResults[subtree.id] = false;
|
||||
this._serverResults[subtree.id] = undefined;
|
||||
this._subtreeErrors[subtree.id] =
|
||||
getWsErrorMessage(err) ?? hass.localize("ui.common.unknown_error");
|
||||
this._recompute();
|
||||
@@ -299,18 +299,19 @@ export class ConditionEvaluatorController implements ReactiveController {
|
||||
}
|
||||
};
|
||||
|
||||
// A failed subtree stays unknown, so it only hides the card when the
|
||||
// result depends on it (a true `or` sibling still wins).
|
||||
const value = this._split.evaluate(clientEvaluator, this._serverResults);
|
||||
const error = firstDefined(this._subtreeErrors);
|
||||
// Don't treat a server error as `false` that a client `not` would invert.
|
||||
if (error !== undefined) {
|
||||
if (value === undefined && error !== undefined) {
|
||||
this._setResult("hidden", error);
|
||||
return;
|
||||
}
|
||||
|
||||
const value = this._split.evaluate(clientEvaluator, this._serverResults);
|
||||
const result: ConditionEvaluation =
|
||||
value === undefined ? "unknown" : value ? "visible" : "hidden";
|
||||
|
||||
this._setResult(result, firstDefined(this._subtreeTemplateErrors));
|
||||
this._setResult(result, error ?? firstDefined(this._subtreeTemplateErrors));
|
||||
}
|
||||
|
||||
private _setResult(
|
||||
|
||||
@@ -3,12 +3,14 @@ import { shouldPolyfill as shouldPolyfillDisplayNames } from "@formatjs/intl-dis
|
||||
import { shouldPolyfill as shouldPolyfillGetCanonicalLocales } from "@formatjs/intl-getcanonicallocales/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillListFormat } from "@formatjs/intl-listformat/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillLocale } from "@formatjs/intl-locale/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillNumberFormat } from "@formatjs/intl-numberformat/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillPluralRules } from "@formatjs/intl-pluralrules/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillRelativeTimeFormat } from "@formatjs/intl-relativetimeformat/should-polyfill";
|
||||
import { shouldPolyfill as shouldPolyfillDurationFormat } from "@formatjs/intl-durationformat/should-polyfill";
|
||||
|
||||
import { getLocalLanguage } from "../../util/common-translation";
|
||||
import {
|
||||
shouldPolyfillNumberFormat,
|
||||
shouldPolyfillPluralRules,
|
||||
} from "./intl-should-polyfill";
|
||||
import {
|
||||
polyfillLocaleData,
|
||||
polyfillTimeZoneData,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// FormatJS 7.1 / 10.1 also probe for formatting numeric strings with
|
||||
// trailingZeroDisplay: "stripToMinimum", which current browsers fail.
|
||||
// That swapped in the English-only PluralRules polyfill everywhere; we only
|
||||
// pass numbers, so leave that probe out.
|
||||
|
||||
const supportsLocale = (
|
||||
supportedLocalesOf: (locales: string[]) => string[],
|
||||
locale: string
|
||||
) => supportedLocalesOf([locale]).length === 1;
|
||||
|
||||
export const shouldPolyfillPluralRules = (locale: string): boolean => {
|
||||
try {
|
||||
return !(
|
||||
typeof Intl.PluralRules === "function" &&
|
||||
// Older engines ignore the fraction digits when choosing the category
|
||||
new Intl.PluralRules("en", { minimumFractionDigits: 2 }).select(1) !==
|
||||
"one" &&
|
||||
supportsLocale(Intl.PluralRules.supportedLocalesOf, locale)
|
||||
);
|
||||
} catch (_err) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Newer than the TypeScript lib this project targets
|
||||
type NumberFormatMethods = Partial<
|
||||
Record<"formatRange" | "formatRangeToParts" | "formatToParts", unknown>
|
||||
>;
|
||||
type RoundingPriorityOptions = Intl.NumberFormatOptions & {
|
||||
roundingPriority?: "auto" | "morePrecision" | "lessPrecision";
|
||||
};
|
||||
|
||||
export const shouldPolyfillNumberFormat = (locale: string): boolean => {
|
||||
try {
|
||||
const prototype: NumberFormatMethods = Intl.NumberFormat.prototype;
|
||||
const roundingPriority: RoundingPriorityOptions = {
|
||||
notation: "compact",
|
||||
minimumSignificantDigits: 3,
|
||||
maximumSignificantDigits: 3,
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
roundingPriority: "morePrecision",
|
||||
};
|
||||
return !(
|
||||
typeof Intl.NumberFormat === "function" &&
|
||||
new Intl.NumberFormat("en", {
|
||||
style: "unit",
|
||||
unit: "bit",
|
||||
unitDisplay: "long",
|
||||
notation: "scientific",
|
||||
}).format(10000) === "1E4 bits" &&
|
||||
new Intl.NumberFormat("en", roundingPriority).format(100000000) ===
|
||||
"100.00M" &&
|
||||
typeof prototype.formatRange === "function" &&
|
||||
typeof prototype.formatRangeToParts === "function" &&
|
||||
typeof prototype.formatToParts === "function" &&
|
||||
Intl.NumberFormat.supportedLocalesOf(["es"]).length === 1 &&
|
||||
supportsLocale(Intl.NumberFormat.supportedLocalesOf, locale)
|
||||
);
|
||||
} catch (_err) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -173,7 +173,7 @@ describe("ConditionEvaluatorController", () => {
|
||||
cond({
|
||||
condition: "not",
|
||||
conditions: [
|
||||
{ condition: "user", users: ["other"] },
|
||||
{ condition: "user", users: ["user1"] },
|
||||
{ condition: "template", value_template: "{{ broken" },
|
||||
],
|
||||
}),
|
||||
@@ -184,6 +184,27 @@ describe("ConditionEvaluatorController", () => {
|
||||
expect(controller.error).toBe("bad");
|
||||
});
|
||||
|
||||
it("shows when an or matches despite a subscription error in another branch", async () => {
|
||||
const { controller } = await setup([
|
||||
cond({
|
||||
condition: "or",
|
||||
conditions: [
|
||||
{ condition: "user", users: ["user1"] },
|
||||
{
|
||||
condition: "or",
|
||||
conditions: [
|
||||
{ condition: "state", entity: "person.a", state: "home" },
|
||||
{ condition: "state", entity: "sensor.missing", state: "on" },
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
]);
|
||||
expect(subs).toHaveLength(1);
|
||||
subs[0].push({ error: "In 'or': unknown entity sensor.missing" });
|
||||
expect(controller.result).toBe("visible");
|
||||
});
|
||||
|
||||
it("surfaces template errors without overriding the result", async () => {
|
||||
// Template render errors are flagged; they don't force hidden.
|
||||
const { controller, last } = await setup([
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
shouldPolyfillNumberFormat,
|
||||
shouldPolyfillPluralRules,
|
||||
} from "../../../src/resources/polyfills/intl-should-polyfill";
|
||||
|
||||
// The PluralRules polyfill only has English data, so replacing a working
|
||||
// native Intl.PluralRules drops plural forms like "few" and "many"
|
||||
describe("Intl polyfill checks", () => {
|
||||
it("works", () => {
|
||||
for (const locale of ["en", "de", "ru", "pl", "ar"]) {
|
||||
expect(shouldPolyfillPluralRules(locale)).toBe(false);
|
||||
expect(shouldPolyfillNumberFormat(locale)).toBe(false);
|
||||
}
|
||||
expect(shouldPolyfillPluralRules("xx")).toBe(true);
|
||||
expect(shouldPolyfillNumberFormat("xx")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -118,15 +118,9 @@
|
||||
"@formatjs/intl-locale/polyfill-force": [
|
||||
"./node_modules/@formatjs/intl-locale/polyfill-force.js"
|
||||
],
|
||||
"@formatjs/intl-numberformat/should-polyfill": [
|
||||
"./node_modules/@formatjs/intl-numberformat/should-polyfill.js"
|
||||
],
|
||||
"@formatjs/intl-numberformat/polyfill-force": [
|
||||
"./node_modules/@formatjs/intl-numberformat/polyfill-force.js"
|
||||
],
|
||||
"@formatjs/intl-pluralrules/should-polyfill": [
|
||||
"./node_modules/@formatjs/intl-pluralrules/should-polyfill.js"
|
||||
],
|
||||
"@formatjs/intl-pluralrules/polyfill-force": [
|
||||
"./node_modules/@formatjs/intl-pluralrules/polyfill-force.js"
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user