From a59dcb845f27d0f540825beb7e38186fc5379ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Sat, 10 Jul 2021 22:38:54 +0200 Subject: [PATCH] no message --- dist/plex-meets-homeassistant.js | 92 ++++++++++++++++-------------- src/plex-meets-homeassistant.ts | 98 +++++++++++++++++--------------- 2 files changed, 100 insertions(+), 90 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index f548b57..7422a99 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -20391,48 +20391,6 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (this.hassObj) { this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection); } - let { entity } = JSON.parse(JSON.stringify(this.config)); - const processEntity = (entityObj, entityString) => { - lodash.forEach(this.entityRegistry, entityInRegister => { - if (lodash.isEqual(entityInRegister.entity_id, entityString)) { - switch (entityInRegister.platform) { - case 'cast': - if (lodash.isNil(entityObj.cast)) { - // eslint-disable-next-line no-param-reassign - entityObj.cast = []; - } - entityObj.cast.push(entityInRegister.entity_id); - break; - case 'androidtv': - if (lodash.isNil(entityObj.androidtv)) { - // eslint-disable-next-line no-param-reassign - entityObj.androidtv = []; - } - entityObj.androidtv.push(entityInRegister.entity_id); - break; - case 'kodi': - if (lodash.isNil(entityObj.kodi)) { - // eslint-disable-next-line no-param-reassign - entityObj.kodi = []; - } - entityObj.kodi.push(entityInRegister.entity_id); - break; - // pass - } - } - }); - }; - const entityOrig = entity; - if (lodash.isString(entityOrig)) { - entity = {}; - processEntity(entity, entityOrig); - } - else if (lodash.isArray(entityOrig)) { - entity = {}; - lodash.forEach(entityOrig, entityStr => { - processEntity(entity, entityStr); - }); - } window.addEventListener('scroll', () => { // todo: improve performance by calculating this when needed only if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this)) { @@ -20495,6 +20453,52 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (this.card) { this.previousPageWidth = this.card.offsetWidth; } + this.renderInitialData(); + this.resizeBackground(); + }; + this.renderInitialData = async () => { + let { entity } = JSON.parse(JSON.stringify(this.config)); + const processEntity = (entityObj, entityString) => { + lodash.forEach(this.entityRegistry, entityInRegister => { + if (lodash.isEqual(entityInRegister.entity_id, entityString)) { + switch (entityInRegister.platform) { + case 'cast': + if (lodash.isNil(entityObj.cast)) { + // eslint-disable-next-line no-param-reassign + entityObj.cast = []; + } + entityObj.cast.push(entityInRegister.entity_id); + break; + case 'androidtv': + if (lodash.isNil(entityObj.androidtv)) { + // eslint-disable-next-line no-param-reassign + entityObj.androidtv = []; + } + entityObj.androidtv.push(entityInRegister.entity_id); + break; + case 'kodi': + if (lodash.isNil(entityObj.kodi)) { + // eslint-disable-next-line no-param-reassign + entityObj.kodi = []; + } + entityObj.kodi.push(entityInRegister.entity_id); + break; + // pass + } + } + }); + }; + const entityOrig = entity; + if (lodash.isString(entityOrig)) { + entity = {}; + processEntity(entity, entityOrig); + } + else if (lodash.isArray(entityOrig)) { + entity = {}; + lodash.forEach(entityOrig, entityStr => { + processEntity(entity, entityStr); + }); + } this.loading = true; this.renderPage(); try { @@ -20587,7 +20591,6 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.error = `Plex server did not respond.
Details of the error: ${escapeHtml(err.message)}`; this.renderPage(); } - this.resizeBackground(); }; this.render = () => { this.renderPage(); @@ -21592,6 +21595,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { return playButton; }; this.setConfig = (config) => { + console.log('setConfig from main'); this.plexProtocol = 'http'; if (!config.entity || config.entity.length === 0) { throw new Error('You need to define at least one entity'); @@ -21644,6 +21648,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.showExtras = config.showExtras; } this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); + this.data = {}; + this.renderInitialData(); }; this.getCardSize = () => { return 3; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index b97c3e9..661a026 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -160,51 +160,6 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.entityRegistry = await fetchEntityRegistry(this.hassObj.connection); } - let { entity } = JSON.parse(JSON.stringify(this.config)); - - const processEntity = (entityObj: Record, entityString: string): void => { - _.forEach(this.entityRegistry, entityInRegister => { - if (_.isEqual(entityInRegister.entity_id, entityString)) { - switch (entityInRegister.platform) { - case 'cast': - if (_.isNil(entityObj.cast)) { - // eslint-disable-next-line no-param-reassign - entityObj.cast = []; - } - entityObj.cast.push(entityInRegister.entity_id); - break; - case 'androidtv': - if (_.isNil(entityObj.androidtv)) { - // eslint-disable-next-line no-param-reassign - entityObj.androidtv = []; - } - entityObj.androidtv.push(entityInRegister.entity_id); - break; - case 'kodi': - if (_.isNil(entityObj.kodi)) { - // eslint-disable-next-line no-param-reassign - entityObj.kodi = []; - } - entityObj.kodi.push(entityInRegister.entity_id); - break; - default: - // pass - } - } - }); - }; - - const entityOrig = entity; - if (_.isString(entityOrig)) { - entity = {}; - processEntity(entity, entityOrig); - } else if (_.isArray(entityOrig)) { - entity = {}; - _.forEach(entityOrig, entityStr => { - processEntity(entity, entityStr); - }); - } - window.addEventListener('scroll', () => { // todo: improve performance by calculating this when needed only if (this.detailsShown && this.activeMovieElem && !isVideoFullScreen(this)) { @@ -269,7 +224,55 @@ class PlexMeetsHomeAssistant extends HTMLElement { if (this.card) { this.previousPageWidth = this.card.offsetWidth; } + this.renderInitialData(); + this.resizeBackground(); + }; + renderInitialData = async (): Promise => { + let { entity } = JSON.parse(JSON.stringify(this.config)); + + const processEntity = (entityObj: Record, entityString: string): void => { + _.forEach(this.entityRegistry, entityInRegister => { + if (_.isEqual(entityInRegister.entity_id, entityString)) { + switch (entityInRegister.platform) { + case 'cast': + if (_.isNil(entityObj.cast)) { + // eslint-disable-next-line no-param-reassign + entityObj.cast = []; + } + entityObj.cast.push(entityInRegister.entity_id); + break; + case 'androidtv': + if (_.isNil(entityObj.androidtv)) { + // eslint-disable-next-line no-param-reassign + entityObj.androidtv = []; + } + entityObj.androidtv.push(entityInRegister.entity_id); + break; + case 'kodi': + if (_.isNil(entityObj.kodi)) { + // eslint-disable-next-line no-param-reassign + entityObj.kodi = []; + } + entityObj.kodi.push(entityInRegister.entity_id); + break; + default: + // pass + } + } + }); + }; + + const entityOrig = entity; + if (_.isString(entityOrig)) { + entity = {}; + processEntity(entity, entityOrig); + } else if (_.isArray(entityOrig)) { + entity = {}; + _.forEach(entityOrig, entityStr => { + processEntity(entity, entityStr); + }); + } this.loading = true; this.renderPage(); try { @@ -366,8 +369,6 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.error = `Plex server did not respond.
Details of the error: ${escapeHtml(err.message)}`; this.renderPage(); } - - this.resizeBackground(); }; render = (): void => { @@ -1489,6 +1490,7 @@ class PlexMeetsHomeAssistant extends HTMLElement { }; setConfig = (config: any): void => { + console.log('setConfig from main'); this.plexProtocol = 'http'; if (!config.entity || config.entity.length === 0) { throw new Error('You need to define at least one entity'); @@ -1541,6 +1543,8 @@ class PlexMeetsHomeAssistant extends HTMLElement { } this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); + this.data = {}; + this.renderInitialData(); }; getCardSize = (): number => {