mirror of
https://github.com/home-assistant/frontend.git
synced 2026-07-02 03:55:52 +01:00
368df82e97
* Redesign the Activity (logbook) as a timeline with entity context * Update color * Refine logbook timeline layout and entry rendering - Three layout modes in ha-logbook-entry: wide (entity → state inline), compact (entity/state + context/time), inline (state + cause icon + time) - Entity name bold in wide and compact modes, consistent with tile card - Cause icon shown inline next to the time in inline (single-entity) mode - Unavailable state rendered as an empty circle dot - Flash icon for entity-triggered causes - "Show more" chevron link in logbook card, device page, and area page - Extract _renderWide / _renderCompact / _renderInline from render() - Scope entity-name flex layout to .line1 > .entity-name (compact only) Co-Authored-By: Paul Bottein <paul.bottein@gmail.com> * Show cause icon in inline logbook entries - Show cause icon (user avatar, trigger type, integration brand) next to the time in single-entity inline mode - Use ha-trigger-icon for trigger-platform causes - Use ha-domain-icon with brand-fallback for integration causes when context_domain is available, falling back to mdiPuzzle - Tooltip with cause name on hover - Icon size 18px, user avatar 18x18px Co-Authored-By: Paul Bottein <paul.bottein@gmail.com> * Adjust cause icon sizes: 18px standalone, 16px inline with text Co-Authored-By: Paul Bottein <paul.bottein@gmail.com> * Fix somes issues * Refine logbook timeline rendering * Fix logbook dot alignment, header link, and graph colors * Use deterministic colors for select/input_select in logbook timeline Assign colors by options list index instead of encounter order so logbook dots always match the history chart colors, regardless of JS chunk boundaries. * Add relative time to logbook entries Show short relative time alongside absolute in all layouts. Cause moves to its own third line in compact when icon mode is active. * Replace dual time display with click-to-toggle in logbook Clicking any time value toggles between absolute (default) and relative short format. State lives in the renderer and propagates via Lit re-render when shouldUpdate allows it. Date headers now show "Today · June 15" and "Yesterday · June 14" for recent dates via Intl.RelativeTimeFormat. * Fix time toggle not updating entries in virtualizer mode Use @queryAll to directly update showRelative on all visible entries after toggling, covering the virtualizer case where Lit re-render alone does not propagate prop changes to already-rendered items. Also remove the !item guard in _renderRow to fix the RenderItemFunction<T> type mismatch. * Refine logbook compact/wide layout and cause display - Move time column to the right in wide layout - Right-align time in compact cause row by wrapping cause+trace in meta-main - Hide cause icon/label for automation and script entries in compact/inline mode (only show trace link) - Make automation/script entity name always clickable (opens more-info) * Refactor logbook cause into typed kinds with text phrases Replace the untyped `iconPath`/`triggerPlatform` fields on `LogbookCause` with a `kind` discriminator (`user`, `automation`, `script`, `state`, `scheduled`, `homeassistant`, `integration`). In timeline layout, causes now render as readable text phrases ("By Paul", "By automation: Mode nuit", "By state change: Porte entrée", "Scheduled", "Via HomeKit") with a `·` separator before "View trace". Entity names in those phrases are clickable when an entity id is available. In list/inline layout, the icon badge uses the kind to pick the right icon (avatar, robot, script, brand domain, puzzle) — no trigger-type icon component needed anymore. * Add show-cause mode to logbook list layout Add a `show-cause` boolean prop to `ha-logbook-entry`, `ha-logbook-renderer`, and `ha-logbook` that switches list mode from a compact icon badge to a full cause phrase on a third line. The third line uses a fixed-width prefix span and a flex-1 truncatable entity button so long automation/script/entity names ellipsize cleanly. The trace link always stays right-aligned on the same line. Enable the mode in `ha-panel-logbook` so the main activity feed shows full cause context for every entry. * Rename logbook model identifiers to match HA conventions and clean up - Rename resolve*/build* → compute*, kind → type, LogbookWhat → LogbookValue, model.what → model.value across model, renderer, and tests - Merge EntryRenderCtx into LogbookRenderItem (extends LogbookItem) so layout methods receive one flat object instead of ctx.model.xxx - Inline _causeUser, drop dead possibleEntity branch in message formatter - Remove unused .cause and .cause-name CSS classes; fix padding-block inconsistency on timeline content * Use ha-relative-time in logbook for auto-updating relative times Replace the static relativeTime() string with <ha-relative-time> so the displayed time updates every 60 s without a full re-render. Add a format prop (Intl.RelativeTimeFormatStyle) to ha-relative-time to support the short style needed by the logbook. Fix text-overflow ellipsis in the time column by restructuring .time to use align-items: stretch with an inner .time-content block that owns overflow/ellipsis, and display: contents on ha-relative-time so its text participates in the parent's inline flow. Also rename computeLogbookItem's internal param from item to entry to avoid shadowing the outer item variable. * Fix automation run value detection and timeline arrow display User-triggered automation runs had context_user_id set but no source or context_event_type, so isAutomationRun was false and the raw backend message "triggered" (lowercase) was shown instead of the localized "Triggered". Add context_user_id to the isAutomationRun check so all automation runs get the proper localized value. Restore the state arrow (→) in the timeline for all value.type === "state" entries, including automation runs. * Fix ha-relative-time interval and use textContent The 60-second auto-update interval was never started when datetime is set via Lit property binding, because connectedCallback runs before Lit sets properties. Move the interval start/stop logic into update() watching the datetime property change instead. Also replace innerHTML with textContent since the relative time string is always plain text. * Remove comments * Feedback
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
localizeTriggerSource,
|
|
parseTriggerSource,
|
|
} from "../../src/data/logbook";
|
|
|
|
const fakeLocalize = ((key: string) => `<${key}>`) as any;
|
|
|
|
describe("localizeTriggerSource", () => {
|
|
it("replaces a known phrase with the bare translation", () => {
|
|
expect(localizeTriggerSource(fakeLocalize, "Home Assistant starting")).toBe(
|
|
"<ui.components.logbook.homeassistant_starting>"
|
|
);
|
|
});
|
|
|
|
it("preserves trailing context after the matched phrase", () => {
|
|
expect(
|
|
localizeTriggerSource(fakeLocalize, "state of binary_sensor.foo")
|
|
).toBe("<ui.components.logbook.state_of> binary_sensor.foo");
|
|
});
|
|
|
|
it("matches 'time pattern' before the shorter 'time' phrase", () => {
|
|
expect(localizeTriggerSource(fakeLocalize, "time pattern")).toBe(
|
|
"<ui.components.logbook.time_pattern>"
|
|
);
|
|
});
|
|
|
|
it("returns the source unchanged when no phrase matches", () => {
|
|
expect(localizeTriggerSource(fakeLocalize, "something else")).toBe(
|
|
"something else"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("parseTriggerSource", () => {
|
|
it("extracts the platform and entity id for state triggers", () => {
|
|
expect(parseTriggerSource("state of binary_sensor.foo")).toEqual({
|
|
platform: "state",
|
|
entityId: "binary_sensor.foo",
|
|
});
|
|
expect(parseTriggerSource("numeric state of sensor.bar")).toEqual({
|
|
platform: "numeric_state",
|
|
entityId: "sensor.bar",
|
|
});
|
|
});
|
|
|
|
it("returns the platform without an entity for time triggers", () => {
|
|
expect(parseTriggerSource("time pattern")).toEqual({
|
|
platform: "time_pattern",
|
|
entityId: undefined,
|
|
});
|
|
expect(parseTriggerSource("time")).toEqual({
|
|
platform: "time",
|
|
entityId: undefined,
|
|
});
|
|
});
|
|
|
|
it("maps Home Assistant start/stop to the homeassistant platform", () => {
|
|
expect(parseTriggerSource("Home Assistant starting")).toEqual({
|
|
platform: "homeassistant",
|
|
entityId: undefined,
|
|
});
|
|
});
|
|
|
|
it("returns an empty result when no phrase matches", () => {
|
|
expect(parseTriggerSource("something else")).toEqual({});
|
|
});
|
|
});
|