From 973ec4684c7f4fb2bc8eb225c4901e066c9f2e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Sun, 3 Oct 2021 22:58:58 +0200 Subject: [PATCH] Fix: Critical error when refreshing state of plexPlayer devices --- dist/plex-meets-homeassistant.js | 22 ++++++++++++++++++---- src/modules/PlayController.ts | 20 ++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 009469d..dd2bd2a 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19858,13 +19858,27 @@ class PlayController { const entityVal = value; if (lodash.isArray(entityVal)) { for (const entity of entityVal) { - // eslint-disable-next-line no-await-in-loop - this.entityStates[entity] = await getState(this.hass, entity); + if (!lodash.isNil(this.hass.states[entity])) { + try { + // eslint-disable-next-line no-await-in-loop + this.entityStates[entity] = await getState(this.hass, entity); + } + catch (err) { + // pass + } + } } } else { - // eslint-disable-next-line no-await-in-loop - this.entityStates[entityVal] = await getState(this.hass, entityVal); + try { + if (!lodash.isNil(this.hass.states[entityVal])) { + // eslint-disable-next-line no-await-in-loop + this.entityStates[entityVal] = await getState(this.hass, entityVal); + } + } + catch (err) { + // pass + } } } try { diff --git a/src/modules/PlayController.ts b/src/modules/PlayController.ts index 9451278..a711eec 100644 --- a/src/modules/PlayController.ts +++ b/src/modules/PlayController.ts @@ -627,12 +627,24 @@ class PlayController { const entityVal = value; if (_.isArray(entityVal)) { for (const entity of entityVal) { - // eslint-disable-next-line no-await-in-loop - this.entityStates[entity] = await getState(this.hass, entity); + if (!_.isNil(this.hass.states[entity])) { + try { + // eslint-disable-next-line no-await-in-loop + this.entityStates[entity] = await getState(this.hass, entity); + } catch (err) { + // pass + } + } } } else { - // eslint-disable-next-line no-await-in-loop - this.entityStates[entityVal] = await getState(this.hass, entityVal); + try { + if (!_.isNil(this.hass.states[entityVal])) { + // eslint-disable-next-line no-await-in-loop + this.entityStates[entityVal] = await getState(this.hass, entityVal); + } + } catch (err) { + // pass + } } } try {