Skip to content

Commit

Permalink
move stateObj.entity_id check to render since it's not defined on set…
Browse files Browse the repository at this point in the history
…Config
  • Loading branch information
Nerwyn committed Oct 18, 2023
1 parent f3cab5e commit 7d41b2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions dist/service-call-tile-feature.js

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

2 changes: 2 additions & 0 deletions src/classes/service-call-button.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HomeAssistant } from 'custom-card-helpers';

import { LitElement, TemplateResult, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';

import { IEntry } from '../models/interfaces';

@customElement('service-call-button')
Expand Down
27 changes: 12 additions & 15 deletions src/service-call-tile-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ console.info(
);

class ServiceCallTileFeature extends LitElement {
@property({ attribute: false })
hass!: HomeAssistant;
@property({ attribute: false })
private config!: IConfig;
@property({ attribute: false })
private stateObj!: HassEntity;
@property({ attribute: false }) hass!: HomeAssistant;
@property({ attribute: false }) private config!: IConfig;
@property({ attribute: false }) private stateObj!: HassEntity;

constructor() {
super();
Expand Down Expand Up @@ -56,15 +53,6 @@ class ServiceCallTileFeature extends LitElement {
...(entry.target || {}),
};

// Set entity ID to tile card entity ID if no other ID is present
if (
!('entity_id' in entry.data) &&
!('device_id' in entry.data) &&
!('area_id' in entry.data)
) {
entry.data['entity_id'] = this.stateObj.entity_id;
}

// Set entry type to button if not present
if (!('type' in entry)) {
(entry as IEntry).type = 'button';
Expand Down Expand Up @@ -159,6 +147,15 @@ class ServiceCallTileFeature extends LitElement {
for (const [itemid, entry] of this.config.entries.entries()) {
let renderedEntry: TemplateResult;

// Set entity ID to tile card entity ID if no other ID is present
if (
!('entity_id' in entry.data!) &&
!('device_id' in entry.data!) &&
!('area_id' in entry.data!)
) {
entry.data!['entity_id'] = this.stateObj.entity_id;
}

const entryType = entry.type;
switch (entryType.toLowerCase()) {
case 'slider':
Expand Down

0 comments on commit 7d41b2f

Please sign in to comment.