Skip to content

Commit

Permalink
1.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Kreeft committed Sep 20, 2022
1 parent 1cad7e0 commit 75625c1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 39 deletions.
5 changes: 5 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% if installed %}

### Features
{% if version_installed.replace("v", "").replace(".","") | int < 139 %}
- Added `Card is tested with jest before making releases`
- Added `Error shown when icon given but show_icon is set to false or not present`
{% endif %}

{% if version_installed.replace("v", "").replace(".","") | int < 138 %}
- Fixed `Bug attribute last-changed and last-updated showing 'never'`
{% 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.3.8",
"version": "1.3.9",
"description": "Show entities in Home Assistant's Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
32 changes: 14 additions & 18 deletions room-card.js

Large diffs are not rendered by default.

Binary file modified room-card.js.gz
Binary file not shown.
3 changes: 1 addition & 2 deletions src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ActionConfig, handleClick, HomeAssistant } from 'custom-card-helpers';
import { HomeAssistantEntity, EntityCondition, RoomCardEntity, RoomCardIcon, RoomCardConfig, EntityStyles } from './types/room-card-types';
import { html, HTMLTemplateResult, LitElement } from 'lit';
import { LAST_CHANGED, LAST_UPDATED, TIMESTAMP_FORMATS } from './lib/constants';
import { createImportSpecifier } from 'typescript';

export const checkConfig = (config: RoomCardConfig) => {
if (config.entities == undefined && config.entity == undefined && config.info_entities == undefined && config.rows == undefined) {
Expand All @@ -26,7 +25,7 @@ export const entityName = (entity: RoomCardEntity) => {

export const entityIcon = (stateObj: HomeAssistantEntity, config: RoomCardEntity | RoomCardConfig, hass: HomeAssistant) => {
if('icon' in config && (config.show_icon === undefined || config.show_icon === false)) {
throw new Error('Icon defined but show_icon is set to false or not defined. Please set show_icon to true');
throw new Error(`Entity: ${config.entity} => Icon defined but show_icon is set to false or not defined. Please set show_icon to true`);
}

if (!('icon' in config)) return stateObj.attributes.icon || null;
Expand Down
36 changes: 20 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { style } from './styles';
import { HomeAssistantEntity, RoomCardConfig, RoomCardEntity, RoomCardRow } from './types/room-card-types';

console.info(
'%c ROOM-CARD %c 1.3.8',
'%c ROOM-CARD %c 1.3.9',
'color: cyan; background: black; font-weight: bold;',
'color: darkblue; background: white; font-weight: bold;'
);
Expand Down Expand Up @@ -67,21 +67,25 @@ export default class RoomCard extends LitElement {
render() : TemplateResult<1> {
if (!this._hass || !this.config) return html``;

return html`
<ha-card elevation="2" style="${entityStyles(this.entity.styles)}">
<div class="card-header">
${renderTitle(this.entity, this.config, this._hass, this)}
<div class="entities-info-row">
${this.info_entities.map((entity) => renderInfoEntity(entity, this._hass, this))}
try {
return html`
<ha-card elevation="2" style="${entityStyles(this.entity.styles)}">
<div class="card-header">
${renderTitle(this.entity, this.config, this._hass, this)}
<div class="entities-info-row">
${this.info_entities.map((entity) => renderInfoEntity(entity, this._hass, this))}
</div>
</div>
</div>
${this.rows !== undefined && this.rows.length > 0 ?
this.rows.map((row) => {
return renderEntitiesRow(row.entities, this._hass, this, "width-100");
})
: renderEntitiesRow(this.entities, this._hass, this)}
${this._refCards}
</ha-card>
`;
${this.rows !== undefined && this.rows.length > 0 ?
this.rows.map((row) => {
return renderEntitiesRow(row.entities, this._hass, this, "width-100");
})
: renderEntitiesRow(this.entities, this._hass, this)}
${this._refCards}
</ha-card>
`;
} catch (error) {
return html`<hui-warning>${error}</hui-warning>`;
}
}
}
18 changes: 18 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ describe('Testing index file class RoomCard', () => {

expect(result).toBeTruthy();
}),
test('Calling render should throw error', () => {

const config: RoomCardConfig = {
entity: 'light.test_entity',
entityIds: ['light.test_entity'],
type: "custom:room-card",
title: 'Test title',
icon: 'mdi:test-icon'
}

roomcard.setConfig(config);
roomcard.hass = hass;

const result = roomcard.render();
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch('<hui-warning></hui-warning>');
}),
test('Calling render without entities, info_entities and rows should return expected html', () => {

const config: RoomCardConfig = {
Expand Down

0 comments on commit 75625c1

Please sign in to comment.