Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
albaintor committed Oct 7, 2024
1 parent a8c1aad commit 566bd1a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/app/active-entities/active-entities.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface Dashboard
})
export class ActiveEntitiesComponent implements OnInit {
remoteState: RemoteState | undefined;
dashboardEntities: MediaEntityState[] = [];
mediaEntities: MediaEntityState[] = [];
protected readonly Math = Math;
menuItems: MenuItem[] = [
Expand All @@ -89,6 +90,7 @@ export class ActiveEntitiesComponent implements OnInit {
showDashboardDialog = false;
dashboardName: string | undefined;
selectedDashboard: Dashboard | undefined;
addNewStates = true;

constructor(private server:ServerService, protected remoteWebsocketService: RemoteWebsocketService,
private cdr:ChangeDetectorRef, private messageService: MessageService,
Expand Down Expand Up @@ -123,7 +125,21 @@ export class ActiveEntitiesComponent implements OnInit {
this.cdr.detectChanges();
})
this.remoteWebsocketService.onMediaStateChange().subscribe(remoteState => {
this.mediaEntities = this.remoteWebsocketService.mediaEntities;
if (this.dashboardEntities)
{
remoteState.forEach(mediaState => {
if (this.mediaEntities.includes(mediaState)) return;
const existingEntity = this.mediaEntities.find(item => item.entity_id === mediaState.entity_id);
if (existingEntity)
{
this.mediaEntities[this.mediaEntities.indexOf(existingEntity)] = mediaState;
}
else if (this.addNewStates)
this.mediaEntities.push(mediaState);
});
}
else
this.mediaEntities = this.remoteWebsocketService.mediaEntities;
this.cdr.detectChanges();
})
this.remoteWebsocketService.onMediaPositionChange().subscribe(entities => {
Expand Down Expand Up @@ -305,14 +321,20 @@ export class ActiveEntitiesComponent implements OnInit {
if (!dashboard || !this.selectedRemote) return;
this.dashboardName = dashboard.name;
this.mediaEntities = [];
this.dashboardEntities = [];
const remote = this.selectedRemote;
dashboard.dashboardEntityIds.forEach(entityId => {
let entity = this.remoteWebsocketService.mediaEntities.find(item => item.entity_id === entityId);
if (!entity) this.server.getRemotetEntity(remote, entityId).subscribe(entity => {
this.mediaEntities.push({...entity, new_state: {attributes: entity.attributes, features: entity.features }} as any);
const mediaState = {...entity, new_state: {attributes: entity.attributes, features: entity.features }} as any;
this.mediaEntities.push(mediaState)
this.dashboardEntities.push(mediaState);
this.cdr.detectChanges();
})
else this.mediaEntities.push(entity);
else {
this.mediaEntities.push(entity);
this.dashboardEntities.push(entity);
}
});
this.selectedActivities = [];
dashboard.popupEntitiyIds.forEach(entityId => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/activity-viewer/activity-viewer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ <h3>Activity</h3>
<div><b>{{item.name}}</b> [<span [style]="{'color': getBackgroundColor(item.entity_type)}">{{item.entity_type}}</span>] ({{item.entity_id}})</div>
</ng-template>
</p-dropdown>
<p-chip *ngFor="let entity of activity?.options?.included_entities" [label]="Helper.getEntityName(entity)"
[style]="getStyle(Helper.getEntityName(entity))" [pTooltip]="entity.entity_id" [removable]="editMode"
<p-chip *ngFor="let entity of activity?.options?.included_entities" label="{{Helper.getEntityName(entity)}} ({{Helper.getEntityType(entity)}})"
[style]="getStyle(Helper.getEntityType(entity))" [pTooltip]="entity.entity_id" [removable]="editMode"
(onRemove)="deleteIncludedEntity(entity, $event)"></p-chip>&nbsp;
</p-toolbar>
<h3>Buttons mapping and startup/stop sequences</h3>
Expand Down
21 changes: 21 additions & 0 deletions src/app/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,27 @@ export class Helper
return "";
}

static getEntityType(entity: any): string
{
if (!entity?.entity_type) return "";
switch(entity.entity_type)
{
case "media_player": return "media player";
case "remote": if (entity.integration && typeof entity.integration === "string") return Helper.getEntityTypeFromIntegration(entity);
if (entity.entity_id.startsWith("uc.main")) return "IR remote";
if (entity.entity_id.startsWith("uc_bt")) return "BR remote";
return "remote";
default:return entity.entity_type;
}
}

static getEntityTypeFromIntegration(entity: any): string
{
if (entity.integration === "uc.main") return "IR remote";
if (entity.integration === "uc_bt.main") return "BT remote";
return entity.entity_type;
}

static isIntersection(rectangle1: {x: number, y: number, width: number, height:number},
rectangle2: {x: number, y: number, width: number, height:number}): boolean
{
Expand Down

0 comments on commit 566bd1a

Please sign in to comment.