Skip to content

Commit

Permalink
Add grid support to person card
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Mar 5, 2024
1 parent f30273e commit 425f16b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/cards/entity-card/entity-card.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, nothing, TemplateResult } from "lit";
import { customElement, state } from "lit/decorators.js";
import { customElement } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { styleMap } from "lit/directives/style-map.js";
import {
Expand Down Expand Up @@ -59,8 +59,7 @@ export class EntityCard extends MushroomBaseCard<EntityCardConfig> implements Lo
return nothing;
}

const entityId = this._config.entity;
const stateObj = this.hass.states[entityId] as HassEntity | undefined;
const stateObj = this._stateObj;

if (!stateObj) {
return this.renderNotFound(this._config);
Expand Down
25 changes: 3 additions & 22 deletions src/cards/person-card/person-card.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HassEntity } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, nothing } from "lit";
import { customElement, state } from "lit/decorators.js";
import { customElement } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { styleMap } from "lit/directives/style-map.js";
import {
Expand Down Expand Up @@ -36,7 +36,7 @@ registerCustomCard({
});

@customElement(PERSON_CARD_NAME)
export class PersonCard extends MushroomBaseCard implements LovelaceCard {
export class PersonCard extends MushroomBaseCard<PersonCardConfig> implements LovelaceCard {
public static async getConfigElement(): Promise<LovelaceCardEditor> {
await import("./person-card-editor");
return document.createElement(PERSON_CARD_EDITOR_NAME) as LovelaceCardEditor;
Expand All @@ -51,24 +51,6 @@ export class PersonCard extends MushroomBaseCard implements LovelaceCard {
};
}

@state() private _config?: PersonCardConfig;

getCardSize(): number | Promise<number> {
return 1;
}

setConfig(config: PersonCardConfig): void {
this._config = {
tap_action: {
action: "more-info",
},
hold_action: {
action: "more-info",
},
...config,
};
}

private _handleAction(ev: ActionHandlerEvent) {
handleAction(this, this.hass!, this._config!, ev.detail.action!);
}
Expand All @@ -78,8 +60,7 @@ export class PersonCard extends MushroomBaseCard implements LovelaceCard {
return nothing;
}

const entityId = this._config.entity;
const stateObj = this.hass.states[entityId] as HassEntity | undefined;
const stateObj = this._stateObj;

if (!stateObj) {
return this.renderNotFound(this._config);
Expand Down

0 comments on commit 425f16b

Please sign in to comment.