diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index aa151f9..9687e7e 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -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 = ''; diff --git a/src/modules/PlayController.ts b/src/modules/PlayController.ts index 074eb64..2cc78e2 100644 --- a/src/modules/PlayController.ts +++ b/src/modules/PlayController.ts @@ -18,15 +18,20 @@ class PlayController { runBefore: Array | false = false; + runAfter: Array | false = false; + supported: any = supported; - constructor(hass: HomeAssistant, plex: Plex, entity: Record, runBefore: string) { + constructor(hass: HomeAssistant, plex: Plex, entity: Record, 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> => { @@ -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> => { diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index e5eaca1..c63e9c9 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -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); };