Skip to content

Commit

Permalink
Get hass object on update
Browse files Browse the repository at this point in the history
  • Loading branch information
fondberg committed Jul 23, 2020
1 parent 9918b3b commit d385a4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions dist/spotify-card.js

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

2 changes: 1 addition & 1 deletion dist/spotify-card.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const CARD_VERSION = '2.0.0-beta.24';
const CARD_VERSION = '2.0.0-beta.25';
export default CARD_VERSION;
25 changes: 15 additions & 10 deletions src/spotify-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
internalProperty,
CSSResult,
TemplateResult,
PropertyValues,
css,
} from 'lit-element';

Expand Down Expand Up @@ -49,8 +50,7 @@ export class SpotifyCard extends LitElement {
return {};
}

@property({ type: Object })
public hass!: HomeAssistant;
@property() public hass!: HomeAssistant;

@property({ type: Object })
public config!: SpotifyCardConfig;
Expand All @@ -69,22 +69,27 @@ export class SpotifyCard extends LitElement {

private unsubscribe_entitites?: any;

doSubscribeEntities() {
this.unsubscribe_entitites = subscribeEntities(this.hass.connection, (entities) => this.entitiesUpdated(entities));
doSubscribeEntities(): void {
if (this.hass?.connection && !this.unsubscribe_entitites && this.isConnected) {
this.unsubscribe_entitites = subscribeEntities(this.hass.connection, (entities) =>
this.entitiesUpdated(entities)
);
}
}

connectedCallback(): void {
super.connectedCallback();
this.spotcast_connector = new SpotcastConnector(this);
//get all available entities and when they update
if (this.hass.connection) {
this.doSubscribeEntities();
} else {
setTimeout(() => this.doSubscribeEntities(), 1000);
}
this.doSubscribeEntities();
}

protected updated(changedProps: PropertyValues): void {
super.updated(changedProps);
this.doSubscribeEntities();
}

public disconnectedCallback() {
public disconnectedCallback(): void {
super.disconnectedCallback();
this.unsubscribe_entitites && this.unsubscribe_entitites();
}
Expand Down

0 comments on commit d385a4a

Please sign in to comment.