Skip to content

Commit

Permalink
Entity not updating passed as string not object (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Kreeft <[email protected]>
  • Loading branch information
marcokreeft87 and Marco Kreeft authored Oct 6, 2022
1 parent f8b4a1d commit ef45d6b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
6 changes: 5 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

### Features

{% if version_installed.replace("v", "").replace(".","") | int < 10612 %}
{% if version_installed.replace("v", "").replace(".","") | int < 10614 %}
- Fixed `Entity not updating when passed as string and not object`
{% endif %}

{% if version_installed.replace("v", "").replace(".","") | int < 10613 %}
- Fixed `Refreshing was not happening in editor and some entities`
{% endif %}

Expand Down
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": "room-card",
"version": "1.06.13",
"version": "1.06.14",
"description": "Show entities in Home Assistant's Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
2 changes: 1 addition & 1 deletion room-card.js

Large diffs are not rendered by default.

Binary file modified room-card.js.gz
Binary file not shown.
10 changes: 7 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ export const hideIfEntity = (entity: RoomCardEntity, hass: HomeAssistant) => {

export const getEntityIds = (config: RoomCardConfig) : string[] =>
[config.entity]
.concat(config.entities?.map((entity) => entity.entity))
.concat(config.info_entities?.map((entity) => entity.entity))
.concat(config.rows?.flatMap(row => row.entities).map((entity) => entity?.entity))
.concat(config.entities?.map((entity) => getEntity(entity)))
.concat(config.info_entities?.map((entity) => getEntity(entity)))
.concat(config.rows?.flatMap(row => row.entities).map((entity) => getEntity(entity)))
.filter((entity) => entity);

export const getEntity = (entity?: string | RoomCardEntity) : string => {
return entity === undefined ? null : typeof entity === 'string' ? entity : entity.entity;
}

export const hasConfigOrEntitiesChanged = (node: RoomCardConfig, changedProps: PropertyValues) => {
if (changedProps.has('config')) {
return true;
Expand Down
20 changes: 20 additions & 0 deletions tests/util/getEntity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createMock } from 'ts-auto-mock';
import { RoomCardEntity } from '../../src/types/room-card-types';
import { getEntity } from '../../src/util';
import { HassEntity } from 'home-assistant-js-websocket';

describe('Testing util file function getEntity', () => {
test('Passing entity string should return entityId', () => {
expect(getEntity('sensor.entity_sensor')).toBe('sensor.entity_sensor');
}),
test('Passing entity object should return entityId', () => {
const entity: RoomCardEntity = {
stateObj: createMock<HassEntity>(),
entity: 'sensor.entity_sensor'
};
expect(getEntity(entity)).toBe('sensor.entity_sensor');
}),
test('Passing entity undefined should return null', () => {
expect(getEntity(undefined)).toBe(null);
})
})

0 comments on commit ef45d6b

Please sign in to comment.