Skip to content

Commit

Permalink
fix: only allow entities with platform="sonos"
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Dec 29, 2023
1 parent 16635c6 commit 9c08d48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/model/store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HomeAssistant } from 'custom-card-helpers';
import HassService from '../services/hass-service';
import MediaBrowseService from '../services/media-browse-service';
import MediaControlService from '../services/media-control-service';
import {
CardConfig,
ConfigPredefinedGroup,
ConfigPredefinedGroupPlayer,
HomeAssistant,
PredefinedGroup,
PredefinedGroupPlayer,
Section,
Expand Down Expand Up @@ -110,7 +110,9 @@ export default class Store {

public getMediaPlayerHassEntities(hass: HomeAssistant) {
const configEntities = [...new Set(this.config.entities)];
return Object.values(hass.states)
return Object.values(this.hass.entities)
.filter((e) => e.entity_id.includes('media_player.') && e.platform === 'sonos')
.map((e) => hass.states[e.entity_id])
.filter(getGroupPlayerIds)
.filter((hassEntity) => {
const includesEntity = configEntities.includes(hassEntity.entity_id);
Expand Down
3 changes: 1 addition & 2 deletions src/services/hass-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { HomeAssistant } from 'custom-card-helpers';
import { MediaPlayerItem, Section, TemplateResult } from '../types';
import { HomeAssistant, MediaPlayerItem, Section, TemplateResult } from '../types';
import { ServiceCallRequest } from 'custom-card-helpers/dist/types';
import { CALL_MEDIA_DONE, CALL_MEDIA_STARTED } from '../constants';
import { MediaPlayer } from '../model/media-player';
Expand Down
11 changes: 10 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LovelaceCardConfig } from 'custom-card-helpers';
import { HomeAssistant as HomeAssistantBase, LovelaceCardConfig } from 'custom-card-helpers';
import { MediaPlayer } from './model/media-player';

declare global {
Expand Down Expand Up @@ -116,3 +116,12 @@ export enum MediaPlayerEntityFeature {
REPEAT_SET = 262144,
GROUPING = 524288,
}

export interface HomeAssistant extends HomeAssistantBase {
entities: { [id: string]: EntityRegistryDisplayEntry };
}

export interface EntityRegistryDisplayEntry {
entity_id: string;
platform?: string;
}

0 comments on commit 9c08d48

Please sign in to comment.