Skip to content

Commit

Permalink
Add hass object to state badge (#314)
Browse files Browse the repository at this point in the history
* Add hass object to state badge

This get's passed to ha-state-icon and is needed to handle changes in:

https://developers.home-assistant.io/blog/2024/01/30/ha-state-icon-properties-changes/

* Fixed unit tests

* Updated info.md

* console.log removal

---------

Co-authored-by: Marco Kreeft <marco.kreeft@gmail.com>
  • Loading branch information
elupus and marcokreeft87 committed Feb 9, 2024
1 parent 22547e6 commit f180f07
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 172 deletions.
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% if installed %}

### Features
{% if version_installed.replace("v", "").replace(".","") | int < 10803 %}
- Fixed `State badges updating again thanks to @elupus`
{% endif %}

{% if version_installed.replace("v", "").replace(".","") | int < 10802 %}
- Fixed `Entity icons not updating on state change`
{% endif %}
Expand Down
176 changes: 171 additions & 5 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "room-card",
"version": "1.08.02",
"version": "1.08.03",
"description": "Show entities in Home Assistant's Lovelace UI",
"keywords": [
"home-assistant",
Expand All @@ -19,6 +19,7 @@
"jest-environment-jsdom": "^29.5.0",
"jest-ts-auto-mock": "^2.1.0",
"lit": "^3.1.0",
"minify-html-literals-loader": "^1.1.1",
"ts-auto-mock": "3.5.0",
"ttypescript": "^1.5.13",
"yarn": "^1.22.18"
Expand Down
128 changes: 1 addition & 127 deletions room-card.js

Large diffs are not rendered by default.

Binary file modified room-card.js.gz
Binary file not shown.
1 change: 1 addition & 0 deletions src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const renderIcon = (stateObj: HomeAssistantEntity, config: RoomCardEntity

return html`<state-badge
class="icon-small ${classes}"
.hass=${hass}
.stateObj="${stateObj}"
.overrideIcon="${isObject(customIcon) ? (customIcon as EntityCondition).icon : customIcon as string}"
.stateColor="${config.state_color}"
Expand Down
4 changes: 2 additions & 2 deletions tests/entity/renderEntitiesRow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Testing entity file function renderEntitiesRow', () => {
const result = renderEntitiesRow(config, entities, hass, element);
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch('<div class="entities-row content-left"><div class="entity" style="" @action=_handleAction .actionHandler=> <span>Test Entity</span> <div><state-badge class="icon-small " .stateObj="" .overrideIcon="mdi:light" .stateColor="" style="" ></state-badge></div> </div></div>');
expect(htmlResult).toMatch('<div class="entities-row content-left"><div class="entity" style="" @action=_handleAction .actionHandler=> <span>Test Entity</span> <div><state-badge class="icon-small " .hass= .stateObj="" .overrideIcon="mdi:light" .stateColor="" style="" ></state-badge></div> </div></div>');
}),
test('Passing entities and classes should return entities-row with one child element', () => {

Expand All @@ -64,6 +64,6 @@ describe('Testing entity file function renderEntitiesRow', () => {
const result = renderEntitiesRow(config, entities, hass, element, 'test-class');
const htmlResult = getRenderString(result);

expect(htmlResult).toMatch('<div class="entities-row content-left test-class"><div class="entity" style="" @action=_handleAction .actionHandler=> <span>Test Entity</span> <div><state-badge class="icon-small " .stateObj="" .overrideIcon="mdi:light" .stateColor="" style="" ></state-badge></div> </div></div>');
expect(htmlResult).toMatch('<div class="entities-row content-left test-class"><div class="entity" style="" @action=_handleAction .actionHandler=> <span>Test Entity</span> <div><state-badge class="icon-small " .hass= .stateObj="" .overrideIcon="mdi:light" .stateColor="" style="" ></state-badge></div> </div></div>');
})
})

0 comments on commit f180f07

Please sign in to comment.