Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@

### Fixed

- **A SPAN Panel card opened while Home Assistant is starting or restarting, or while the integration retries a panel it cannot reach, says it is waiting for
the panel to load and draws the panel once it has loaded**, where it showed "Unable to connect to SPAN Panel" until Retry was pressed or the dashboard was
opened again.
- **The sidebar dashboard, opened while Home Assistant is starting or restarting or while the integration retries a panel it cannot reach, says it is waiting
for the panel to load and draws the panel once it has loaded**, where it showed errors, monitoring as off or missing favorites meanwhile, and could miss the
panel's unreachable warning.
- **A SPAN Panel card or the sidebar dashboard whose panel failed to set up, as when it must be authenticated again, cannot load until Home Assistant is
restarted, or is disabled, says so and how to set it right, and draws the panel once it has loaded**, where the card showed "Unable to connect to SPAN Panel"
and the sidebar "SPAN Panel integration is not loaded", monitoring as off or no favorites.
- **A SPAN Panel card left on a dashboard after its panel was removed says it is unable to connect**, where it drew an empty card.
- **The card and the sidebar dashboard show a panel's monitoring again once a reload of the panel, as after its options are changed, finishes**, where a view
drawn or a circuit's side panel opened during the reload could show monitoring as off until opened again.
- **The sidebar dashboard says no SPAN Panel is found where there is none**, where it showed "Panel device not found. Check device_id in card config."
- **The sidebar dashboard's panel list catches up once the connection to Home Assistant is back**, where a panel added, removed or renamed just as the
connection was lost stayed listed as it was until the next change.
- **The Monitoring tab's Event Bus help lists every key of the `span_panel_current_alert` event**, the new `alert_display_name`, the circuit's name as Home
Assistant shows it, among them, where it left out the keys for the monitoring rating, the copied package ratings and when the overload began.
- **While Home Assistant is starting, or keeps retrying a panel it can't reach, the SPAN Panel card and the sidebar dashboard say they're waiting for the panel
and show it as soon as it's ready.** Before, the card said "Unable to connect to SPAN Panel" until you pressed Retry, and the sidebar showed errors,
monitoring as off, or no favorites.
- **When a panel can't start because it needs you to sign in again, needs Home Assistant restarted, or is disabled, the card and the sidebar dashboard now say
so and what to do, and show the panel once it starts.** Before, the card said "Unable to connect to SPAN Panel" and the sidebar "SPAN Panel integration is not
loaded".
- **A SPAN Panel card left on a dashboard after you remove its panel now says it can't connect, and the sidebar dashboard says when you have no SPAN Panel.**
Before, the card was blank and the sidebar showed "Panel device not found. Check device_id in card config."
- **After a panel reloads, for example when you change its options, the card and the sidebar dashboard show its monitoring again.** Before, anything opened
during the reload could show monitoring as off until you opened it again.
- **The sidebar dashboard's list of panels updates once the connection to Home Assistant comes back.** Before, a panel added, removed or renamed while the
connection was down stayed listed as it was.
- **The Monitoring tab's Event Bus help now says what the `span_panel_current_alert` event is for, and links to the full list of its fields.** Before, it showed
a bare list of field names.

## 0.12.0

Expand Down
4 changes: 2 additions & 2 deletions dist/span-panel-card.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/span-panel.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "span-panel-card",
"version": "0.12.1-beta.3",
"version": "0.12.1-beta.4",
"private": true,
"type": "module",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { t } from "./i18n.js";
import type { ChartMetricDef, GraphHorizonPreset, SheddingPriorityDef } from "./types.js";

export const CARD_VERSION = "0.12.1-beta.3";
export const CARD_VERSION = "0.12.1-beta.4";

// -- Defaults --

Expand Down Expand Up @@ -53,6 +53,12 @@ export const SUB_DEVICE_KEY_PREFIX = "sub_";
*/
export const TANDEM_GUIDE_URL = "https://github.com/SpanPanel/span/blob/main/tandems.md#main-32";

/**
* The integration's documentation of the Monitoring view's Notification Settings, which lists every field of the
* `span_panel_current_alert` event; the Event Bus help links to it. It names `main`, so the link follows the newest list.
*/
export const ALERT_EVENT_FIELDS_URL = "https://github.com/SpanPanel/span/blob/main/frontend.md#notification-settings";

// -- Chart layout constants --

export const CIRCUIT_CHART_HEIGHT = 100;
Expand Down
25 changes: 15 additions & 10 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ const translations: Record<string, Record<string, string>> = {
"notification.title_template": "Title Template",
"notification.message_template": "Message Template",
"notification.placeholders": "Placeholders:",
"notification.event_bus_help": "Event Bus fires event type",
"notification.event_bus_payload": "with payload:",
"notification.event_bus_help":
"With the Event Bus selected, each alert also fires the {event} event, carrying the circuit's name, the alert type, the current, the ratings and when it happened.",
"notification.event_bus_fields": "See all of its fields.",
"notification.test_label": "Test Notification",
"notification.test_button": "Send Test",
"notification.test_sending": "Sending...",
Expand Down Expand Up @@ -384,8 +385,9 @@ const translations: Record<string, Record<string, string>> = {
"notification.title_template": "Plantilla de T\u00edtulo",
"notification.message_template": "Plantilla de Mensaje",
"notification.placeholders": "Variables:",
"notification.event_bus_help": "El Bus de Eventos dispara el tipo de evento",
"notification.event_bus_payload": "con datos:",
"notification.event_bus_help":
"Con el Bus de Eventos seleccionado, cada alerta tambi\u00e9n dispara el evento {event}, con el nombre del circuito, el tipo de alerta, la corriente, los calibres y cu\u00e1ndo ocurri\u00f3.",
"notification.event_bus_fields": "Vea todos sus campos.",
"notification.test_label": "Notificaci\u00f3n de prueba",
"notification.test_button": "Enviar prueba",
"notification.test_sending": "Enviando...",
Expand Down Expand Up @@ -674,8 +676,9 @@ const translations: Record<string, Record<string, string>> = {
"notification.title_template": "Mod\u00e8le de Titre",
"notification.message_template": "Mod\u00e8le de Message",
"notification.placeholders": "Variables :",
"notification.event_bus_help": "Le Bus d'\u00e9v\u00e9nements d\u00e9clenche le type d'\u00e9v\u00e9nement",
"notification.event_bus_payload": "avec les donn\u00e9es :",
"notification.event_bus_help":
"Lorsque le Bus d'\u00e9v\u00e9nements est s\u00e9lectionn\u00e9, chaque alerte d\u00e9clenche aussi l'\u00e9v\u00e9nement {event}, qui indique le nom du circuit, le type d'alerte, le courant, les calibres et le moment o\u00f9 elle s'est produite.",
"notification.event_bus_fields": "Voir tous ses champs.",
"notification.test_label": "Notification de test",
"notification.test_button": "Envoyer un test",
"notification.test_sending": "Envoi...",
Expand Down Expand Up @@ -968,8 +971,9 @@ const translations: Record<string, Record<string, string>> = {
"notification.title_template": "\u30bf\u30a4\u30c8\u30eb\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8",
"notification.message_template": "\u30e1\u30c3\u30bb\u30fc\u30b8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8",
"notification.placeholders": "\u30d7\u30ec\u30fc\u30b9\u30db\u30eb\u30c0\u30fc:",
"notification.event_bus_help": "\u30a4\u30d9\u30f3\u30c8\u30d0\u30b9\u304c\u767a\u884c\u3059\u308b\u30a4\u30d9\u30f3\u30c8\u30bf\u30a4\u30d7",
"notification.event_bus_payload": "\u30da\u30a4\u30ed\u30fc\u30c9:",
"notification.event_bus_help":
"\u30a4\u30d9\u30f3\u30c8\u30d0\u30b9\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u5404\u30a2\u30e9\u30fc\u30c8\u306f {event} \u30a4\u30d9\u30f3\u30c8\u3082\u767a\u884c\u3057\u307e\u3059\u3002\u56de\u8def\u540d\u3001\u30a2\u30e9\u30fc\u30c8\u306e\u7a2e\u985e\u3001\u96fb\u6d41\u3001\u5b9a\u683c\u3001\u767a\u751f\u6642\u523b\u3092\u542b\u307f\u307e\u3059\u3002",
"notification.event_bus_fields": "\u3059\u3079\u3066\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u898b\u308b\u3002",
"notification.test_label": "\u30c6\u30b9\u30c8\u901a\u77e5",
"notification.test_button": "\u30c6\u30b9\u30c8\u9001\u4fe1",
"notification.test_sending": "\u9001\u4fe1\u4e2d...",
Expand Down Expand Up @@ -1285,8 +1289,9 @@ const translations: Record<string, Record<string, string>> = {
"notification.title_template": "Modelo de T\u00edtulo",
"notification.message_template": "Modelo de Mensagem",
"notification.placeholders": "Vari\u00e1veis:",
"notification.event_bus_help": "O Barramento de Eventos dispara o tipo de evento",
"notification.event_bus_payload": "com dados:",
"notification.event_bus_help":
"Com o Barramento de Eventos selecionado, cada alerta tamb\u00e9m dispara o evento {event}, com o nome do circuito, o tipo de alerta, a corrente, as correntes nominais e quando ocorreu.",
"notification.event_bus_fields": "Veja todos os seus campos.",
"notification.test_label": "Notifica\u00e7\u00e3o de teste",
"notification.test_button": "Enviar teste",
"notification.test_sending": "Enviando...",
Expand Down
23 changes: 15 additions & 8 deletions src/panel/tab-monitoring.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INTEGRATION_DOMAIN, INPUT_DEBOUNCE_MS, TANDEM_GUIDE_URL } from "../constants.js";
import { ALERT_EVENT_FIELDS_URL, INTEGRATION_DOMAIN, INPUT_DEBOUNCE_MS, TANDEM_GUIDE_URL } from "../constants.js";
import { escapeHtml } from "../helpers/sanitize.js";
import { attrSelectorValue } from "../helpers/selector.js";
import { errorText, serviceErrorMessage } from "../helpers/error-text.js";
Expand Down Expand Up @@ -437,6 +437,19 @@ function sameWarnings(a: ReadonlyMap<string, CopyWarning>, b: ReadonlyMap<string
return a.size === b.size && [...a].every(([entity, warning]) => b.get(entity) === warning);
}

/**
* The help under the notification templates for whoever writes an automation on the Event Bus: what the
* `span_panel_current_alert` event carries, in words, and a link that opens the integration's list of its fields in a
* new tab. The translated sentence is escaped before the event's name is put in its `{event}` place, so the name is
* the only markup it holds.
*/
function eventBusHelpHTML(): string {
const sentence = escapeHtml(t("notification.event_bus_help")).replace("{event}", "<code>span_panel_current_alert</code>");
const fields = `<a href="${escapeHtml(ALERT_EVENT_FIELDS_URL)}" target="_blank" rel="noopener noreferrer"
style="${LINK_STYLE}">${escapeHtml(t("notification.event_bus_fields"))}</a>`;
return `${sentence} ${fields}`;
}

/**
* The note above the table on a panel that takes copies (spec §14.6): why a
* MAIN 32's tandems raise false alerts, and how to copy their ratings from the
Expand Down Expand Up @@ -1118,13 +1131,7 @@ export class MonitoringTab {
<code>{utilization_pct}</code> <code>{window_m}</code> <code>{local_time}</code>
</div>
<div style="font-size:0.75em;color:var(--secondary-text-color);margin-top:6px;line-height:1.4;">
${t("notification.event_bus_help")} <code>span_panel_current_alert</code>
${t("notification.event_bus_payload")} <code>alert_source</code> <code>alert_id</code>
<code>alert_name</code> <code>alert_display_name</code> <code>alert_type</code> <code>current_a</code>
<code>breaker_rating_a</code> <code>monitoring_rating_a</code> <code>monitoring_rating_user_set</code>
<code>package_ratings_a</code> <code>package_ratings_state</code> <code>threshold_pct</code>
<code>utilization_pct</code> <code>panel_serial</code> <code>local_time</code>
<code>window_duration_s</code> <code>over_threshold_since</code>
${eventBusHelpHTML()}
</div>

<div style="display:flex;align-items:center;gap:10px;margin-top:12px;">
Expand Down
72 changes: 38 additions & 34 deletions tests/monitoring-tab-event-help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,12 @@ import type { HomeAssistant } from "../src/types.js";
import { ErrorStore } from "../src/core/error-store.js";

// With the Event Bus among its notify targets, the integration fires
// `span_panel_current_alert` for each alert, and the Monitoring tab's notification
// settings list the keys of its payload for whoever writes an automation on it.
// `span_panel_current_alert` for each alert. The Monitoring tab's notification
// settings name the event for whoever writes an automation on it, say in words
// what it carries, and link to the integration's documentation for its fields.

/** The keys of the payload `dispatch_alert` fires, in its order; the last two only where the alert has them. */
const PAYLOAD_KEYS = [
"alert_source",
"alert_id",
"alert_name",
"alert_display_name",
"alert_type",
"current_a",
"breaker_rating_a",
"monitoring_rating_a",
"monitoring_rating_user_set",
"package_ratings_a",
"package_ratings_state",
"threshold_pct",
"utilization_pct",
"panel_serial",
"local_time",
"window_duration_s",
"over_threshold_since",
];
/** The integration's list of the event's fields, under the Monitoring view's Notification Settings. */
const FIELDS_URL = "https://github.com/SpanPanel/span/blob/main/frontend.md#notification-settings";

/** An administrator's Home Assistant whose panel has monitoring on, with the Event Bus among its targets. */
function hass(): HomeAssistant {
Expand Down Expand Up @@ -59,20 +42,41 @@ afterEach(() => {
for (const el of mounted.splice(0)) el.remove();
});

/** Render the tab in `language` and return the element holding the event's help. */
async function eventHelp(language: string): Promise<HTMLElement | null | undefined> {
setLanguage(language);
const host = document.createElement("div");
document.body.appendChild(host);
mounted.push(host);
const container = document.createElement("div");
host.attachShadow({ mode: "open" }).appendChild(container);

await new MonitoringTab(new ErrorStore()).render(container, hass(), "entry-1", null);

return [...container.querySelectorAll("code")].find(code => code.textContent === "span_panel_current_alert")?.parentElement;
}

describe("the Monitoring tab's help for the Event Bus", () => {
it("names the event and lists every key of its payload, the circuit's name as Home Assistant shows it included", async () => {
const host = document.createElement("div");
document.body.appendChild(host);
mounted.push(host);
const container = document.createElement("div");
host.attachShadow({ mode: "open" }).appendChild(container);
it("names the event, says what it carries and links to its fields", async () => {
const help = await eventHelp("en");

expect(help?.textContent?.replace(/\s+/g, " ").trim()).toBe(
"With the Event Bus selected, each alert also fires the span_panel_current_alert event, carrying the circuit's name, " +
"the alert type, the current, the ratings and when it happened. See all of its fields."
);
// The event is the only name it shows: no list of the payload's keys.
expect([...(help?.querySelectorAll("code") ?? [])].map(code => code.textContent)).toEqual(["span_panel_current_alert"]);
const links = [...(help?.querySelectorAll("a") ?? [])];
expect(links.map(link => [link.textContent, link.getAttribute("href"), link.getAttribute("target"), link.getAttribute("rel")])).toEqual([
["See all of its fields.", FIELDS_URL, "_blank", "noopener noreferrer"],
]);
});

await new MonitoringTab(new ErrorStore()).render(container, hass(), "entry-1", null);
it.each(["es", "fr", "ja", "pt"])("names the event and links to its fields in %s", async language => {
const help = await eventHelp(language);

// The line that names the event, and holds the keys after it.
const help = [...container.querySelectorAll("code")].find(code => code.textContent === "span_panel_current_alert")?.parentElement;
expect(help?.textContent).toContain("Event Bus fires event type");
const codes = [...(help?.querySelectorAll("code") ?? [])].map(code => code.textContent);
expect(codes).toEqual(["span_panel_current_alert", ...PAYLOAD_KEYS]);
expect(help?.textContent).not.toContain("{event}");
expect([...(help?.querySelectorAll("code") ?? [])].map(code => code.textContent)).toEqual(["span_panel_current_alert"]);
expect([...(help?.querySelectorAll("a") ?? [])].map(link => link.getAttribute("href"))).toEqual([FIELDS_URL]);
});
});
Loading