ha-nunjucks 1.7.1 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { addFilters } from './filters';
4
4
  import { addGlobals } from './globals';
5
5
  import { handleWhenReady } from './helpers';
6
6
  import { addTests } from './tests';
7
- import { fetchConfigEntries } from './utils/config_entry';
7
+ import { subscribeConfigEntries } from './utils/config_entry';
8
8
  import { fetchEntityRegistry } from './utils/entities';
9
9
  import { fetchRepairsIssues } from './utils/issues';
10
10
  import { fetchLabelRegistry } from './utils/labels';
@@ -29,33 +29,30 @@ if (version(packageInfo.version).compare(window.haNunjucks.version || '0.0.0') >
29
29
  ...window.haNunjucks,
30
30
  hass: ha.hass,
31
31
  labelRegistry: {
32
- event: 'label_registry_updated',
32
+ updateEvent: 'label_registry_updated',
33
33
  fetchRegistry: fetchLabelRegistry,
34
34
  labelId: {},
35
35
  name2LabelId: {},
36
36
  },
37
37
  entityRegistry: {
38
- event: 'entity_registry_updated',
38
+ updateEvent: 'entity_registry_updated',
39
39
  fetchRegistry: fetchEntityRegistry,
40
40
  entityId2ConfigEntryId: {},
41
41
  configEntryId2EntityIds: {},
42
42
  },
43
- configEntries: {
44
- event: 'config_entries/subscribe',
45
- fetchRegistry: fetchConfigEntries,
46
- entryId: {},
47
- title2EntryId: {},
48
- },
49
43
  repairsIssues: {
50
- event: 'repairs/list_issues',
44
+ updateEvent: 'repairs_issue_registry_updated',
51
45
  fetchRegistry: fetchRepairsIssues,
52
46
  issues: {},
53
47
  },
48
+ configEntries: {
49
+ entryId: {},
50
+ title2EntryId: {},
51
+ },
54
52
  };
55
53
  const registries = [
56
54
  'labelRegistry',
57
55
  'entityRegistry',
58
- 'configEntries',
59
56
  'repairsIssues',
60
57
  ];
61
58
  for (const registry of registries) {
@@ -65,8 +62,9 @@ if (version(packageInfo.version).compare(window.haNunjucks.version || '0.0.0') >
65
62
  window.haNunjucks[registry].timeout = setTimeout(() => {
66
63
  window.haNunjucks[registry].fetchRegistry(ha.hass);
67
64
  }, 500);
68
- }, window.haNunjucks[registry].event);
65
+ }, window.haNunjucks[registry].updateEvent);
69
66
  }
67
+ subscribeConfigEntries(ha.hass);
70
68
  // States object
71
69
  buildStatesObject();
72
70
  // Number and datetime translators
@@ -80,6 +78,7 @@ if (version(packageInfo.version).compare(window.haNunjucks.version || '0.0.0') >
80
78
  window.haNunjucks.datetimeFormat = new Intl.DateTimeFormat(ha.hass.language, { dateStyle: 'full', timeStyle: 'long' });
81
79
  window.haNunjucks.ordinalFormat = new Intl.PluralRules('en-US', // ha.hass.language, // Use english for proper numeric suffixes
82
80
  { type: 'ordinal' });
81
+ console.info(`%c HA-NUNJUCKS v${packageInfo.version}`, 'color: white; font-weight: bold; background: darkgreen');
83
82
  }, () => {
84
83
  const ha = document.querySelector('home-assistant');
85
84
  return ha?.hass?.connected && ha?.hass?.connection?.connected;
@@ -153,6 +153,10 @@ export interface ConfigEntry {
153
153
  error_reason_translation_key?: string;
154
154
  error_reason_translation_placeholders?: Record<string, string>;
155
155
  }
156
+ export interface ConfigEntryUpdate {
157
+ type: null | 'added' | 'removed' | 'updated';
158
+ entry: ConfigEntry;
159
+ }
156
160
  export interface RepairsIssue {
157
161
  domain: string;
158
162
  issue_domain?: string;
@@ -1,5 +1,5 @@
1
1
  import { HomeAssistant } from '../models/interfaces/hass';
2
- export declare function fetchConfigEntries(hass: HomeAssistant): Promise<void>;
2
+ export declare function subscribeConfigEntries(hass: HomeAssistant): Promise<void>;
3
3
  export declare function config_entry_id(entity_id: string): string;
4
4
  declare const ConfigEntryAttributes: readonly ["domain", "title", "state", "source", "disabled_by"];
5
5
  type ConfigEntryAttribute = (typeof ConfigEntryAttributes)[number];
@@ -1,19 +1,37 @@
1
- export async function fetchConfigEntries(hass) {
2
- const entries = await hass.callWS({
3
- type: 'config_entries/get',
1
+ export async function subscribeConfigEntries(hass) {
2
+ await hass.connection.subscribeMessage((updates) => {
3
+ const entryId = window.haNunjucks.configEntries.entryId || {};
4
+ const title2EntryId = window.haNunjucks.configEntries.title2EntryId || {};
5
+ for (const update of updates) {
6
+ if (update.type == 'removed') {
7
+ delete entryId[update.entry.entry_id];
8
+ if (title2EntryId[update.entry.title]) {
9
+ title2EntryId[update.entry.title] = title2EntryId[update.entry.title].filter((id) => id != update.entry.entry_id);
10
+ if (!title2EntryId[update.entry.title].length) {
11
+ delete title2EntryId[update.entry.title];
12
+ }
13
+ }
14
+ }
15
+ else {
16
+ if (entryId[update.entry.entry_id] &&
17
+ entryId[update.entry.entry_id].title != update.entry.title) {
18
+ delete title2EntryId[entryId[update.entry.entry_id].title];
19
+ }
20
+ entryId[update.entry.entry_id] = update.entry;
21
+ title2EntryId[update.entry.title] ??= [];
22
+ if (!title2EntryId[update.entry.title].includes(update.entry.entry_id)) {
23
+ title2EntryId[update.entry.title].push(update.entry.entry_id);
24
+ }
25
+ }
26
+ }
27
+ window.haNunjucks.configEntries = {
28
+ ...window.haNunjucks.configEntries,
29
+ entryId,
30
+ title2EntryId,
31
+ };
32
+ }, {
33
+ type: 'config_entries/subscribe',
4
34
  });
5
- const entryId = {};
6
- const title2EntryId = {};
7
- for (const entry of entries) {
8
- entryId[entry.entry_id] = entry;
9
- title2EntryId[entry.title] ??= [];
10
- title2EntryId[entry.title].push(entry.entry_id);
11
- }
12
- window.haNunjucks.configEntries = {
13
- ...window.haNunjucks.configEntries,
14
- entryId,
15
- title2EntryId,
16
- };
17
35
  }
18
36
  export function config_entry_id(entity_id) {
19
37
  return window.haNunjucks.entityRegistry.entityId2ConfigEntryId[entity_id];
@@ -4,7 +4,9 @@ export async function fetchRepairsIssues(hass) {
4
4
  })).issues;
5
5
  const issues = {};
6
6
  for (const issue of repairsIssues) {
7
- issues[`${issue.issue_domain || issue.domain},${issue.issue_id}`] = issue;
7
+ if (!issue.ignored) {
8
+ issues[`${issue.issue_domain || issue.domain},${issue.issue_id}`] = issue;
9
+ }
8
10
  }
9
11
  window.haNunjucks.repairsIssues.issues = issues;
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ha-nunjucks",
3
- "version": "1.7.1",
3
+ "version": "1.7.4",
4
4
  "description": "Wrapper for nunjucks for use with Home Assistant frontend custom components to render templates",
5
5
  "main": "./dist/index.js",
6
6
  "files": [