diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 364e12e..b3b3026 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19459,6 +19459,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.playTrailer = document.createElement('paper-dropdown-menu'); this.showExtras = document.createElement('paper-dropdown-menu'); this.showSearch = document.createElement('paper-dropdown-menu'); + this.runBefore = document.createElement('paper-dropdown-menu'); + this.runAfter = document.createElement('paper-dropdown-menu'); this.devicesTabs = 0; this.entities = []; this.scriptEntities = []; @@ -19528,6 +19530,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { else if (lodash.isEqual(this.showSearch.value, 'No')) { this.config.showSearch = false; } + this.config.runBefore = this.runBefore.value; + this.config.runAfter = this.runAfter.value; } if (!lodash.isEqual(this.config, originalConfig)) { this.fireEvent(this, 'config-changed', { config: this.config }); @@ -19571,7 +19575,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.scriptEntities.push(key); } }); - console.log(this.scriptEntities); this.entitiesRegistry = await fetchEntityRegistry(this.hassObj.connection); } this.entities = []; @@ -19742,6 +19745,32 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } this.showSearch.value = showSearchValue; this.plexValidSection.appendChild(this.showSearch); + this.runBefore.innerHTML = ''; + const runBeforeItems = document.createElement('paper-listbox'); + runBeforeItems.appendChild(addDropdownItem('')); + lodash.forEach(this.scriptEntities, entity => { + runBeforeItems.appendChild(addDropdownItem(entity)); + }); + runBeforeItems.slot = 'dropdown-content'; + this.runBefore.label = 'Script to execute before starting the media'; + this.runBefore.appendChild(runBeforeItems); + this.runBefore.style.width = '100%'; + this.runBefore.addEventListener('value-changed', this.valueUpdated); + this.runBefore.value = this.config.runBefore; + this.plexValidSection.appendChild(this.runBefore); + this.runAfter.innerHTML = ''; + const runAfterItems = document.createElement('paper-listbox'); + runAfterItems.appendChild(addDropdownItem('')); + lodash.forEach(this.scriptEntities, entity => { + runAfterItems.appendChild(addDropdownItem(entity)); + }); + runAfterItems.slot = 'dropdown-content'; + this.runAfter.label = 'Script to execute after starting the media'; + this.runAfter.appendChild(runAfterItems); + this.runAfter.style.width = '100%'; + this.runAfter.addEventListener('value-changed', this.valueUpdated); + this.runAfter.value = this.config.runAfter; + this.plexValidSection.appendChild(this.runAfter); let hasUIConfig = true; let canConvert = true; if (lodash.isArray(this.config.entity)) { @@ -19862,6 +19891,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { else { this.config.showSearch = true; } + if (!lodash.isNil(config.runBefore)) { + this.config.runBefore = config.runBefore; + } + if (!lodash.isNil(config.runAfter)) { + this.config.runAfter = config.runAfter; + } this.render(); }; this.configChanged = (newConfig) => { @@ -21911,10 +21946,10 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (config.maxCount && config.maxCount !== '') { this.maxCount = config.maxCount; } - if (config.runBefore) { + if (config.runBefore && !lodash.isEqual(config.runBefore, '')) { this.runBefore = config.runBefore; } - if (config.runAfter) { + if (config.runAfter && !lodash.isEqual(config.runAfter, '')) { this.runAfter = config.runAfter; } if (!lodash.isNil(config.playTrailer)) { diff --git a/src/editor.ts b/src/editor.ts index 443a6ec..fac646f 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -40,6 +40,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { showSearch: any = document.createElement('paper-dropdown-menu'); + runBefore: any = document.createElement('paper-dropdown-menu'); + + runAfter: any = document.createElement('paper-dropdown-menu'); + devicesTabs = 0; hassObj: HomeAssistant | undefined; @@ -120,6 +124,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } else if (_.isEqual(this.showSearch.value, 'No')) { this.config.showSearch = false; } + this.config.runBefore = this.runBefore.value; + this.config.runAfter = this.runAfter.value; } if (!_.isEqual(this.config, originalConfig)) { this.fireEvent(this, 'config-changed', { config: this.config }); @@ -166,7 +172,6 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.scriptEntities.push(key); } }); - console.log(this.scriptEntities); this.entitiesRegistry = await fetchEntityRegistry(this.hassObj.connection); } @@ -350,6 +355,34 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.showSearch.value = showSearchValue; this.plexValidSection.appendChild(this.showSearch); + this.runBefore.innerHTML = ''; + const runBeforeItems: any = document.createElement('paper-listbox'); + runBeforeItems.appendChild(addDropdownItem('')); + _.forEach(this.scriptEntities, entity => { + runBeforeItems.appendChild(addDropdownItem(entity)); + }); + runBeforeItems.slot = 'dropdown-content'; + this.runBefore.label = 'Script to execute before starting the media'; + this.runBefore.appendChild(runBeforeItems); + this.runBefore.style.width = '100%'; + this.runBefore.addEventListener('value-changed', this.valueUpdated); + this.runBefore.value = this.config.runBefore; + this.plexValidSection.appendChild(this.runBefore); + + this.runAfter.innerHTML = ''; + const runAfterItems: any = document.createElement('paper-listbox'); + runAfterItems.appendChild(addDropdownItem('')); + _.forEach(this.scriptEntities, entity => { + runAfterItems.appendChild(addDropdownItem(entity)); + }); + runAfterItems.slot = 'dropdown-content'; + this.runAfter.label = 'Script to execute after starting the media'; + this.runAfter.appendChild(runAfterItems); + this.runAfter.style.width = '100%'; + this.runAfter.addEventListener('value-changed', this.valueUpdated); + this.runAfter.value = this.config.runAfter; + this.plexValidSection.appendChild(this.runAfter); + let hasUIConfig = true; let canConvert = true; if (_.isArray(this.config.entity)) { @@ -473,6 +506,14 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.config.showSearch = true; } + if (!_.isNil(config.runBefore)) { + this.config.runBefore = config.runBefore; + } + + if (!_.isNil(config.runAfter)) { + this.config.runAfter = config.runAfter; + } + this.render(); }; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 1a4dc80..d851810 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -1551,10 +1551,10 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (config.maxCount && config.maxCount !== '') { this.maxCount = config.maxCount; } - if (config.runBefore) { + if (config.runBefore && !_.isEqual(config.runBefore, '')) { this.runBefore = config.runBefore; } - if (config.runAfter) { + if (config.runAfter && !_.isEqual(config.runAfter, '')) { this.runAfter = config.runAfter; } if (!_.isNil(config.playTrailer)) {