Skip to content

Commit

Permalink
disable _states, may be causing performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerwyn committed Sep 21, 2024
1 parent 65ae2e7 commit ab7d16f
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 155 deletions.
3 changes: 1 addition & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import nunjucks from 'nunjucks';
import { addFilters } from './filters';
import { addGlobals } from './globals';
import { addTests } from './tests';
import { buildStatesObject } from './utils/states';
nunjucks.installJinjaCompat();
const env = addTests(addFilters(addGlobals(new nunjucks.Environment())));
/**
Expand All @@ -19,7 +18,7 @@ export function renderTemplate(hass, str, context) {
str = env
.renderString(structuredClone(str), {
hass,
_states: buildStatesObject(hass),
// _states: buildStatesObject(hass),
...context,
})
.trim();
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import nunjucks from 'nunjucks';
import { addFilters } from './filters';
import { addGlobals } from './globals';
import { addTests } from './tests';
import { buildStatesObject } from './utils/states';

nunjucks.installJinjaCompat();
const env = addTests(addFilters(addGlobals(new nunjucks.Environment())));
Expand All @@ -29,7 +28,7 @@ export function renderTemplate(
str = env
.renderString(structuredClone(str), {
hass,
_states: buildStatesObject(hass),
// _states: buildStatesObject(hass),
...context,
})
.trim();
Expand Down
4 changes: 2 additions & 2 deletions tests/renderTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ describe('renderTemplate', () => {
assert.equal(
renderTemplate(
hass,
'{{ _states.light.lounge.attributes.min_mireds }}',
'{{ hass.states["light.lounge"].attributes.min_mireds }}',
context,
),
153,
);
assert.equal(
renderTemplate(
hass,
'The {{ min }} color temperature is {{ _states.light.lounge.attributes.min_mireds }} mireds. Also I\'m {{ doThing("my taxes") }}',
'The {{ min }} color temperature is {{ hass.states["light.lounge"].attributes.min_mireds }} mireds. Also I\'m {{ doThing("my taxes") }}',
context,
),
"The minimum color temperature is 153 mireds. Also I'm doing my taxes!",
Expand Down
114 changes: 57 additions & 57 deletions tests/utils/distance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ describe('closest', () => {
);
});

it('should return the closest entity to home if given _states', () => {
assert.equal(
renderTemplate(hass, '{{ closest(_states).entity_id }}'),
'person.john_doe',
);
});
// it('should return the closest entity to home if given _states', () => {
// assert.equal(
// renderTemplate(hass, '{{ closest(_states).entity_id }}'),
// 'person.john_doe',
// );
// });

it('should return the closest entity to home if given _states.domain', () => {
assert.equal(
renderTemplate(
hass,
'{{ closest(_states.device_tracker).entity_id }}',
),
'device_tracker.ark_of_the_covenent',
);
});
// it('should return the closest entity to home if given _states.domain', () => {
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest(_states.device_tracker).entity_id }}',
// ),
// 'device_tracker.ark_of_the_covenent',
// );
// });

it('should return the closest entity in a domain if given one', () => {
assert.equal(
Expand Down Expand Up @@ -129,13 +129,13 @@ describe('closest', () => {
),
'person.jane_doe',
);
assert.equal(
renderTemplate(
hass,
'{{ closest(_states.zone.danger).entity_id }}',
),
'person.jane_doe',
);
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest(_states.zone.danger).entity_id }}',
// ),
// 'person.jane_doe',
// );
});
});

Expand All @@ -148,20 +148,20 @@ describe('closest', () => {
),
'device_tracker.null_island',
);
assert.equal(
renderTemplate(
hass,
'{{ closest("zone.danger", _states).entity_id }}',
),
'device_tracker.null_island',
);
assert.equal(
renderTemplate(
hass,
'{{ closest("zone.danger", _states.person).entity_id }}',
),
'person.john_doe',
);
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest("zone.danger", _states).entity_id }}',
// ),
// 'device_tracker.null_island',
// );
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest("zone.danger", _states.person).entity_id }}',
// ),
// 'person.john_doe',
// );
assert.equal(
renderTemplate(
hass,
Expand All @@ -186,20 +186,20 @@ describe('closest', () => {
),
'device_tracker.ark_of_the_covenent',
);
assert.equal(
renderTemplate(
hass,
'{{ closest(31, 31, _states).entity_id }}',
),
'device_tracker.ark_of_the_covenent',
);
assert.equal(
renderTemplate(
hass,
'{{ closest(31, 31, _states.person).entity_id }}',
),
'person.jane_doe',
);
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest(31, 31, _states).entity_id }}',
// ),
// 'device_tracker.ark_of_the_covenent',
// );
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest(31, 31, _states.person).entity_id }}',
// ),
// 'person.jane_doe',
// );
assert.equal(
renderTemplate(
hass,
Expand Down Expand Up @@ -232,13 +232,13 @@ describe('closest', () => {
),
'person.jane_doe',
);
assert.equal(
renderTemplate(
hass,
'{{ closest(31, 31, _states.zone.danger).entity_id }}',
),
'person.jane_doe',
);
// assert.equal(
// renderTemplate(
// hass,
// '{{ closest(31, 31, _states.zone.danger).entity_id }}',
// ),
// 'person.jane_doe',
// );
});
});
});
Loading

0 comments on commit ab7d16f

Please sign in to comment.