Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration unavailable card #172

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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