Skip to content

Commit

Permalink
Fix integration unavailable card (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek authored May 17, 2023
1 parent 5685667 commit 6fb9e2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/meteoalarm-card.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LitElement, html, TemplateResult, PropertyValues, CSSResultGroup } from 'lit';
import { customElement, property, state } from 'lit/decorators';
import {ifDefined} from 'lit/directives/if-defined';
import {
HomeAssistant,
hasConfigOrEntityChanged,
Expand Down Expand Up @@ -297,13 +298,13 @@ export class MeteoalarmCard extends LitElement {
// from the selected integration, sometimes doing additional processing and checks
private getEvents(): MeteoalarmAlertParsed[] {
// If any entity is unavailable show unavailable card
const unavailableEntity = this.entities.find(e => {
return (e.attributes.status || e.attributes.state || e.state) === 'unavailable';
const unavailableEntity = this.entities.some(e => {
return e == undefined || (e.attributes.status || e.attributes.state || e.state) === 'unavailable';
});
if(unavailableEntity) {
return [{
isActive: false,
entity: unavailableEntity,
entity: undefined,
icon: 'cloud-question',
color: MeteoalarmData.getLevel(MeteoalarmLevelType.None).color,
headlines: [
Expand Down Expand Up @@ -463,7 +464,7 @@ export class MeteoalarmCard extends LitElement {
<div
class="swiper-slide"
style="background-color: ${event.color}; color: ${event.isActive ? '#fff' : 'inherit'}"
entity_id=${event.entity.entity_id}
entity_id=${ifDefined(event.entity?.entity_id)}
>
<div class="content">
${this.renderMainIcon(event.icon)}
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export interface MeteoalarmAlert {
// Event transformed from MeteoalarmEvent used for rendering card
export interface MeteoalarmAlertParsed {
isActive: boolean,
entity: HassEntity,
icon: string,
color: string,
headlines: string[],
captionIcon?: string,
caption?: string
caption?: string,
entity?: HassEntity,
}

// This list is ordered how dangerous events are
Expand Down

0 comments on commit 6fb9e2b

Please sign in to comment.