2.0
Juraj Nyíri 3 years ago
parent a59dcb845f
commit a7c8ba1916

@ -19451,6 +19451,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.ip = document.createElement('paper-input'); this.ip = document.createElement('paper-input');
this.token = document.createElement('paper-input'); this.token = document.createElement('paper-input');
this.port = document.createElement('paper-input'); this.port = document.createElement('paper-input');
this.maxCount = document.createElement('paper-input');
this.libraryName = document.createElement('paper-dropdown-menu'); this.libraryName = document.createElement('paper-dropdown-menu');
this.tabs = document.createElement('paper-tabs'); this.tabs = document.createElement('paper-tabs');
this.devicesTabs = 0; this.devicesTabs = 0;
@ -19476,6 +19477,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.token = this.token.value; this.config.token = this.token.value;
this.config.port = this.port.value; this.config.port = this.port.value;
this.config.libraryName = this.libraryName.value; this.config.libraryName = this.libraryName.value;
if (lodash.isEmpty(this.maxCount.value)) {
this.config.maxCount = '';
}
else {
this.config.maxCount = parseInt(this.maxCount.value, 10);
}
if (!lodash.isEmpty(this.entities)) { if (!lodash.isEmpty(this.entities)) {
this.config.entity = []; this.config.entity = [];
lodash.forEach(this.entities, entity => { lodash.forEach(this.entities, entity => {
@ -19542,6 +19549,11 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.port.type = 'number'; this.port.type = 'number';
this.port.addEventListener('change', this.valueUpdated); this.port.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.port); this.content.appendChild(this.port);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.maxCount);
this.libraryName.innerHTML = ''; this.libraryName.innerHTML = '';
const libraryItems = document.createElement('paper-listbox'); const libraryItems = document.createElement('paper-listbox');
libraryItems.appendChild(addDropdownItem('Continue Watching')); libraryItems.appendChild(addDropdownItem('Continue Watching'));
@ -20376,6 +20388,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.maxCount = false; this.maxCount = false;
this.error = ''; this.error = '';
this.contentBGHeight = 0; this.contentBGHeight = 0;
this.initialDataLoaded = false;
this.renderNewElementsIfNeeded = () => { this.renderNewElementsIfNeeded = () => {
const loadAdditionalRowsCount = 2; // todo: make this configurable const loadAdditionalRowsCount = 2; // todo: make this configurable
const height = getHeight(this.content); const height = getHeight(this.content);
@ -20453,8 +20466,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.card) { if (this.card) {
this.previousPageWidth = this.card.offsetWidth; this.previousPageWidth = this.card.offsetWidth;
} }
this.renderInitialData();
this.resizeBackground(); this.resizeBackground();
this.initialDataLoaded = true;
}; };
this.renderInitialData = async () => { this.renderInitialData = async () => {
let { entity } = JSON.parse(JSON.stringify(this.config)); let { entity } = JSON.parse(JSON.stringify(this.config));
@ -21595,7 +21608,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
return playButton; return playButton;
}; };
this.setConfig = (config) => { this.setConfig = (config) => {
console.log('setConfig from main');
this.plexProtocol = 'http'; this.plexProtocol = 'http';
if (!config.entity || config.entity.length === 0) { if (!config.entity || config.entity.length === 0) {
throw new Error('You need to define at least one entity'); throw new Error('You need to define at least one entity');
@ -21632,7 +21644,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.port) { if (config.port) {
this.plexPort = config.port; this.plexPort = config.port;
} }
if (config.maxCount) { if (config.maxCount && config.maxCount !== '') {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
if (config.runBefore) { if (config.runBefore) {
@ -21657,11 +21669,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
} }
set hass(hass) { set hass(hass) {
this.hassObj = hass; this.hassObj = hass;
if (!this.content) { if (!this.initialDataLoaded) {
this.error = ''; this.loadInitialData();
if (!this.loading) {
this.loadInitialData();
}
} }
} }
static getConfigElement() { static getConfigElement() {

@ -22,6 +22,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
port: any = document.createElement('paper-input'); port: any = document.createElement('paper-input');
maxCount: any = document.createElement('paper-input');
libraryName: any = document.createElement('paper-dropdown-menu'); libraryName: any = document.createElement('paper-dropdown-menu');
tabs: any = document.createElement('paper-tabs'); tabs: any = document.createElement('paper-tabs');
@ -62,6 +64,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.config.token = this.token.value; this.config.token = this.token.value;
this.config.port = this.port.value; this.config.port = this.port.value;
this.config.libraryName = this.libraryName.value; this.config.libraryName = this.libraryName.value;
if (_.isEmpty(this.maxCount.value)) {
this.config.maxCount = '';
} else {
this.config.maxCount = parseInt(this.maxCount.value, 10);
}
if (!_.isEmpty(this.entities)) { if (!_.isEmpty(this.entities)) {
this.config.entity = []; this.config.entity = [];
_.forEach(this.entities, entity => { _.forEach(this.entities, entity => {
@ -137,6 +145,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.port.addEventListener('change', this.valueUpdated); this.port.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.port); this.content.appendChild(this.port);
this.maxCount.label = 'Maximum number of items to display';
this.maxCount.value = this.config.maxCount;
this.maxCount.type = 'number';
this.maxCount.addEventListener('change', this.valueUpdated);
this.content.appendChild(this.maxCount);
this.libraryName.innerHTML = ''; this.libraryName.innerHTML = '';
const libraryItems: any = document.createElement('paper-listbox'); const libraryItems: any = document.createElement('paper-listbox');
libraryItems.appendChild(addDropdownItem('Continue Watching')); libraryItems.appendChild(addDropdownItem('Continue Watching'));

@ -125,14 +125,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
card: HTMLElement | undefined; card: HTMLElement | undefined;
initialDataLoaded = false;
set hass(hass: HomeAssistant) { set hass(hass: HomeAssistant) {
this.hassObj = hass; this.hassObj = hass;
if (!this.content) { if (!this.initialDataLoaded) {
this.error = ''; this.loadInitialData();
if (!this.loading) {
this.loadInitialData();
}
} }
} }
@ -224,8 +223,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.card) { if (this.card) {
this.previousPageWidth = this.card.offsetWidth; this.previousPageWidth = this.card.offsetWidth;
} }
this.renderInitialData();
this.resizeBackground(); this.resizeBackground();
this.initialDataLoaded = true;
}; };
renderInitialData = async (): Promise<void> => { renderInitialData = async (): Promise<void> => {
@ -1490,7 +1489,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}; };
setConfig = (config: any): void => { setConfig = (config: any): void => {
console.log('setConfig from main');
this.plexProtocol = 'http'; this.plexProtocol = 'http';
if (!config.entity || config.entity.length === 0) { if (!config.entity || config.entity.length === 0) {
throw new Error('You need to define at least one entity'); throw new Error('You need to define at least one entity');
@ -1526,7 +1524,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.port) { if (config.port) {
this.plexPort = config.port; this.plexPort = config.port;
} }
if (config.maxCount) { if (config.maxCount && config.maxCount !== '') {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
if (config.runBefore) { if (config.runBefore) {

Loading…
Cancel
Save