From b738269d8dd12c6a41442b92c4e5ea24befa51f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Sat, 16 Oct 2021 14:34:31 +0200 Subject: [PATCH] Add: Support for plexPlayer in input_select and input_text. --- DETAILED_CONFIGURATION.md | 4 ++-- dist/plex-meets-homeassistant.js | 12 ++++++++---- src/modules/PlayController.ts | 12 ++++++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/DETAILED_CONFIGURATION.md b/DETAILED_CONFIGURATION.md index 4eba3e3..b95ee0f 100644 --- a/DETAILED_CONFIGURATION.md +++ b/DETAILED_CONFIGURATION.md @@ -25,8 +25,8 @@ You can also use Live TV library by specifying its name, usually "Live TV & DVR" - **kodi**: Entity id of your media_player configured via [Kodi](https://www.home-assistant.io/integrations/kodi/). See [detailed instructions](#kodi). It is also possible to use short declaration with kodi. - **plexPlayer**: Name or machine ID of your plex client. Use this if you do not have devices above. See [detailed instructions](#all-other-plex-clients). It is required to use detailed declaration with "plexPlayer:" property. - **cast**: Entity id of your media_player configured via [Google Cast](https://www.home-assistant.io/integrations/cast/). See [detailed instructions](#google-cast). It is also possible to use short declaration with cast. -- **input_select**: Entity id of input select you wish to use for selecting media player to play on. State of this entity needs to be entity ID of media player of `androidtv`, `kodi` or `cast`. It is currently not possible to combine this with `plexPlayer`. -- **input_text**: Entity id of input text you wish to use for selecting media player to play on. State of this entity needs to be entity ID of media player of `androidtv`, `kodi` or `cast`. It is currently not possible to combine this with `plexPlayer`. +- **input_select**: Entity id of input select you wish to use for selecting media player to play on. State of this entity needs to be entity ID of media player of `androidtv`, `kodi` or `cast`. You can also use this with `plexPlayer`, in that case, provide name or machine ID of your plex client. You can also provide the same string as displayed in entities selection in UI editor for the card (beginning with `plexPlayer |`). +- **input_text**: Entity id of input text you wish to use for selecting media player to play on. State of this entity needs to be entity ID of media player of `androidtv`, `kodi` or `cast`. You can also use this with `plexPlayer`, in that case, provide name or machine ID of your plex client. You can also provide the same string as displayed in entities selection in UI editor for the card (beginning with `plexPlayer |`). **port**: _Optional_ Port of your plex sever. diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 1ac24c2..f37454b 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19887,7 +19887,7 @@ class PlayController { if (lodash.isArray(entityID)) { for (let i = 0; i < entityID.length; i += 1) { const realEntityID = lodash.get(this.entityStates[entityID[i]], 'state'); - let realEntityKey = 'unknown'; + let realEntityKey = 'plexPlayer'; lodash.forEach(this.entityRegistry, entityInRegister => { if (lodash.isEqual(entityInRegister.entity_id, realEntityID)) { realEntityKey = entityInRegister.platform; @@ -19901,7 +19901,7 @@ class PlayController { } else { const realEntityID = lodash.get(this.entityStates[entityID], 'state'); - let realEntityKey = 'unknown'; + let realEntityKey = 'plexPlayer'; lodash.forEach(this.entityRegistry, entityInRegister => { if (lodash.isEqual(entityInRegister.entity_id, realEntityID)) { realEntityKey = entityInRegister.platform; @@ -20049,14 +20049,18 @@ class PlayController { return this.entityStates; }; this.getPlexPlayerMachineIdentifier = (entity) => { + if (lodash.isString(entity) && lodash.isEqual(entity.split(' | ').length, 4)) { + // eslint-disable-next-line no-param-reassign + [, , , entity] = entity.split(' | '); + } let machineIdentifier = ''; let { plex } = this; let entityName = ''; if (lodash.isString(entity)) { - entityName = entity; + entityName = entity.trim(); } else if (lodash.isObjectLike(entity) && !lodash.isNil(entity.identifier)) { - entityName = entity.identifier; + entityName = entity.identifier.trim(); if (!lodash.isNil(entity.plex) && entity.plex) { plex = entity.plex; } diff --git a/src/modules/PlayController.ts b/src/modules/PlayController.ts index b68d32f..233a229 100644 --- a/src/modules/PlayController.ts +++ b/src/modules/PlayController.ts @@ -592,7 +592,7 @@ class PlayController { if (_.isArray(entityID)) { for (let i = 0; i < entityID.length; i += 1) { const realEntityID = _.get(this.entityStates[entityID[i]], 'state'); - let realEntityKey = 'unknown'; + let realEntityKey = 'plexPlayer'; _.forEach(this.entityRegistry, entityInRegister => { if (_.isEqual(entityInRegister.entity_id, realEntityID)) { realEntityKey = entityInRegister.platform; @@ -605,7 +605,7 @@ class PlayController { } } else { const realEntityID = _.get(this.entityStates[entityID], 'state'); - let realEntityKey = 'unknown'; + let realEntityKey = 'plexPlayer'; _.forEach(this.entityRegistry, entityInRegister => { if (_.isEqual(entityInRegister.entity_id, realEntityID)) { realEntityKey = entityInRegister.platform; @@ -769,14 +769,18 @@ class PlayController { }; private getPlexPlayerMachineIdentifier = (entity: string | Record): string => { + if (_.isString(entity) && _.isEqual(entity.split(' | ').length, 4)) { + // eslint-disable-next-line no-param-reassign + [, , , entity] = entity.split(' | '); + } let machineIdentifier = ''; let { plex } = this; let entityName = ''; if (_.isString(entity)) { - entityName = entity; + entityName = entity.trim(); } else if (_.isObjectLike(entity) && !_.isNil(entity.identifier)) { - entityName = entity.identifier; + entityName = entity.identifier.trim(); if (!_.isNil(entity.plex) && entity.plex) { plex = entity.plex; }