mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-24 12:49:19 +00:00
Add support for entity translation key (#14482)
This commit is contained in:
@@ -31,7 +31,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"component.binary_sensor.state._.off"
|
||||
);
|
||||
});
|
||||
@@ -45,7 +45,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"component.binary_sensor.state.moisture.off"
|
||||
);
|
||||
});
|
||||
@@ -65,7 +65,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"component.binary_sensor.state.invalid_device_class.off"
|
||||
);
|
||||
});
|
||||
@@ -79,7 +79,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"123 m"
|
||||
);
|
||||
});
|
||||
@@ -93,7 +93,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"1,234.5 m"
|
||||
);
|
||||
});
|
||||
@@ -107,7 +107,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"1,234.5"
|
||||
);
|
||||
});
|
||||
@@ -127,7 +127,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"state.default.unknown"
|
||||
);
|
||||
});
|
||||
@@ -147,7 +147,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
@@ -165,7 +165,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"component.sensor.state._.custom_state"
|
||||
);
|
||||
});
|
||||
@@ -187,14 +187,14 @@ describe("computeStateDisplay", () => {
|
||||
};
|
||||
it("Uses am/pm time format", () => {
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"November 18, 2017 at 11:12 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"November 18, 2017 at 23:12"
|
||||
);
|
||||
});
|
||||
@@ -216,7 +216,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"November 18, 2017"
|
||||
);
|
||||
});
|
||||
@@ -239,14 +239,14 @@ describe("computeStateDisplay", () => {
|
||||
it("Uses am/pm time format", () => {
|
||||
localeData.time_format = TimeFormat.am_pm;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"11:12 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
"23:12"
|
||||
);
|
||||
});
|
||||
@@ -273,6 +273,7 @@ describe("computeStateDisplay", () => {
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
{},
|
||||
"2021-07-04 15:40:03"
|
||||
),
|
||||
"July 4, 2021 at 3:40 PM"
|
||||
@@ -285,6 +286,7 @@ describe("computeStateDisplay", () => {
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
{},
|
||||
"2021-07-04 15:40:03"
|
||||
),
|
||||
"July 4, 2021 at 15:40"
|
||||
@@ -308,7 +310,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, "2021-07-04"),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "2021-07-04"),
|
||||
"July 4, 2021"
|
||||
);
|
||||
});
|
||||
@@ -331,14 +333,14 @@ describe("computeStateDisplay", () => {
|
||||
it("Uses am/pm time format", () => {
|
||||
localeData.time_format = TimeFormat.am_pm;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, "17:05:07"),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||
"5:05 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, "17:05:07"),
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||
"17:05"
|
||||
);
|
||||
});
|
||||
@@ -357,7 +359,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
@@ -372,8 +374,26 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
"My Custom State"
|
||||
);
|
||||
});
|
||||
|
||||
it("Localizes using translation key", () => {
|
||||
const stateObj: any = {
|
||||
entity_id: "sensor.test",
|
||||
state: "custom_state",
|
||||
attributes: {},
|
||||
};
|
||||
const entities: any = {
|
||||
"sensor.test": {
|
||||
translation_key: "custom_translation",
|
||||
platform: "custom_integration",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, entities),
|
||||
"component.custom_integration.entity.sensor.custom_translation.state.custom_state"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user