From c743d0a2aa9ddd623bf44fa2096fede66e0b569b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Thu, 2 Sep 2021 22:37:23 +0200 Subject: [PATCH] Update: Clean up Plex IP Address / Hostname from protocol and trailing slashes --- dist/plex-meets-homeassistant.js | 8 ++++---- src/editor.ts | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 1450540..c5ebaa0 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -19699,7 +19699,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.valueUpdated = () => { const originalConfig = lodash.clone(this.config); this.config.protocol = this.protocol.value; - this.config.ip = this.ip.value; + this.config.ip = this.ip.value.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.config.token = this.token.value; this.config.port = this.port.value; if (this.loaded) { @@ -19867,8 +19867,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.protocol.value = this.config.protocol; } this.content.appendChild(this.protocol); - this.ip.label = 'Plex IP Address'; - this.ip.value = this.config.ip; + this.ip.label = 'Plex IP Address / Hostname'; + this.ip.value = this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.ip.addEventListener('change', this.valueUpdated); this.content.appendChild(this.ip); this.port.label = 'Plex Port (Optional)'; @@ -19898,7 +19898,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.content.appendChild(this.libraryName); this.content.appendChild(warningLibrary); this.appendChild(this.content); - this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); + this.plex = new Plex(this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''), this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.sections = await this.plex.getSections(); this.livetv = await this.plex.getLiveTV(); this.collections = await this.plex.getCollections(); diff --git a/src/editor.ts b/src/editor.ts index 0904995..8d8513b 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -95,7 +95,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { valueUpdated = (): void => { const originalConfig = _.clone(this.config); this.config.protocol = this.protocol.value; - this.config.ip = this.ip.value; + this.config.ip = this.ip.value.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.config.token = this.token.value; this.config.port = this.port.value; if (this.loaded) { @@ -266,8 +266,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } this.content.appendChild(this.protocol); - this.ip.label = 'Plex IP Address'; - this.ip.value = this.config.ip; + this.ip.label = 'Plex IP Address / Hostname'; + this.ip.value = this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''); this.ip.addEventListener('change', this.valueUpdated); this.content.appendChild(this.ip); @@ -304,7 +304,13 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { this.appendChild(this.content); - this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); + this.plex = new Plex( + this.config.ip.replace(/^https?\:\/\//i, '').replace(/\/$/, ''), + this.plexPort, + this.config.token, + this.plexProtocol, + this.config.sort + ); this.sections = await this.plex.getSections(); this.livetv = await this.plex.getLiveTV(); this.collections = await this.plex.getCollections();