Add: runAfter parameter

pull/16/head
Juraj Nyíri 4 years ago
parent 52c3ce67de
commit 31898a24a5

@ -18830,9 +18830,10 @@ class Plex {
}
class PlayController {
constructor(hass, plex, entity, runBefore) {
constructor(hass, plex, entity, runBefore, runAfter) {
this.plexPlayerEntity = '';
this.runBefore = false;
this.runAfter = false;
this.supported = supported;
this.getState = async (entityID) => {
return this.hass.callApi('GET', `states/${entityID}`);
@ -18912,6 +18913,9 @@ class PlayController {
default:
throw Error(`No service available to play ${data.title}!`);
}
if (lodash.isArray(this.runAfter)) {
await this.hass.callService(this.runAfter[0], this.runAfter[1], {});
}
};
this.plexPlayerCreateQueue = async (movieID) => {
const url = `${this.plex.protocol}://${this.plex.ip}:${this.plex.port}/playQueues?type=video&shuffle=0&repeat=0&continuous=1&own=1&uri=server://${await this.plex.getServerID()}/com.plexapp.plugins.library/library/metadata/${movieID}`;
@ -19112,6 +19116,9 @@ class PlayController {
if (!lodash.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.');
}
if (!lodash.isEmpty(runAfter) && this.hass.states[runAfter]) {
this.runAfter = runAfter.split('.');
}
}
}
@ -19910,6 +19917,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.plexProtocol = 'http';
this.detailsShown = false;
this.runBefore = '';
this.runAfter = '';
this.columnsCount = 0;
this.renderedItems = 0;
this.maxRenderCount = false;
@ -21033,6 +21041,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.runBefore) {
this.runBefore = config.runBefore;
}
if (config.runAfter) {
this.runAfter = config.runAfter;
}
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort);
};
this.getCardSize = () => {
@ -21042,7 +21053,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
set hass(hass) {
this.hassObj = hass;
if (this.plex) {
this.playController = new PlayController(this.hassObj, this.plex, this.config.entity, this.runBefore);
this.playController = new PlayController(this.hassObj, this.plex, this.config.entity, this.runBefore, this.runAfter);
}
if (!this.content) {
this.error = '';

@ -18,15 +18,20 @@ class PlayController {
runBefore: Array<string> | false = false;
runAfter: Array<string> | false = false;
supported: any = supported;
constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>, runBefore: string) {
constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>, runBefore: string, runAfter: string) {
this.hass = hass;
this.plex = plex;
this.entity = entity;
if (!_.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.');
}
if (!_.isEmpty(runAfter) && this.hass.states[runAfter]) {
this.runAfter = runAfter.split('.');
}
}
private getState = async (entityID: string): Promise<Record<string, any>> => {
@ -111,6 +116,9 @@ class PlayController {
default:
throw Error(`No service available to play ${data.title}!`);
}
if (_.isArray(this.runAfter)) {
await this.hass.callService(this.runAfter[0], this.runAfter[1], {});
}
};
private plexPlayerCreateQueue = async (movieID: number): Promise<Record<string, number>> => {

@ -25,6 +25,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
runBefore = '';
runAfter = '';
renderNewElementsIfNeededTimeout: any;
columnsCount = 0;
@ -108,7 +110,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
set hass(hass: HomeAssistant) {
this.hassObj = hass;
if (this.plex) {
this.playController = new PlayController(this.hassObj, this.plex, this.config.entity, this.runBefore);
this.playController = new PlayController(
this.hassObj,
this.plex,
this.config.entity,
this.runBefore,
this.runAfter
);
}
if (!this.content) {
@ -1346,6 +1354,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.runBefore) {
this.runBefore = config.runBefore;
}
if (config.runAfter) {
this.runAfter = config.runAfter;
}
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort);
};

Loading…
Cancel
Save