2.0
Juraj Nyíri 3 years ago
parent f2a870cc50
commit 9015086217

@ -19466,6 +19466,7 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.entities = []; this.entities = [];
this.scriptEntities = []; this.scriptEntities = [];
this.sections = []; this.sections = [];
this.clients = {};
this.entitiesRegistry = false; this.entitiesRegistry = false;
this.plexValidSection = document.createElement('div'); this.plexValidSection = document.createElement('div');
this.loaded = false; this.loaded = false;
@ -19560,13 +19561,29 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
const entitiesDropDown = document.createElement('paper-dropdown-menu'); const entitiesDropDown = document.createElement('paper-dropdown-menu');
const entities = document.createElement('paper-listbox'); const entities = document.createElement('paper-listbox');
entities.appendChild(addDropdownItem('')); entities.appendChild(addDropdownItem(''));
const addedEntityStrings = [];
lodash.forEach(this.entitiesRegistry, entityRegistry => { lodash.forEach(this.entitiesRegistry, entityRegistry => {
if (lodash.isEqual(entityRegistry.platform, 'cast') || if (lodash.isEqual(entityRegistry.platform, 'cast') ||
lodash.isEqual(entityRegistry.platform, 'kodi') || lodash.isEqual(entityRegistry.platform, 'kodi') ||
lodash.isEqual(entityRegistry.platform, 'androidtv')) { lodash.isEqual(entityRegistry.platform, 'androidtv')) {
entities.appendChild(addDropdownItem(entityRegistry.entity_id)); const entityName = `${entityRegistry.platform} | ${entityRegistry.entity_id}`;
entities.appendChild(addDropdownItem(entityName));
addedEntityStrings.push(entityName);
} }
}); });
lodash.forEach(this.clients, value => {
const entityName = `plexPlayer | ${value.name} | ${value.address} | ${value.machineIdentifier}`;
entities.appendChild(addDropdownItem(entityName));
addedEntityStrings.push(entityName);
});
if (lodash.isArray(this.config.entity)) {
lodash.forEach(this.config.entity, value => {
if (!lodash.includes(addedEntityStrings, value)) {
entities.appendChild(addDropdownItem(value));
addedEntityStrings.push(value);
}
});
}
entities.slot = 'dropdown-content'; entities.slot = 'dropdown-content';
entitiesDropDown.label = 'Entity'; entitiesDropDown.label = 'Entity';
entitiesDropDown.value = selected; entitiesDropDown.value = selected;
@ -19639,12 +19656,12 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.libraryName.addEventListener('value-changed', this.valueUpdated); this.libraryName.addEventListener('value-changed', this.valueUpdated);
this.content.appendChild(this.libraryName); this.content.appendChild(this.libraryName);
this.appendChild(this.content); this.appendChild(this.content);
// todo: do verify better, do not query plex every time
this.sections = [];
this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
this.sections = await this.plex.getSections(); this.sections = await this.plex.getSections();
this.clients = await this.plex.getClients();
this.plexValidSection.style.display = 'none'; this.plexValidSection.style.display = 'none';
this.plexValidSection.innerHTML = ''; this.plexValidSection.innerHTML = '';
// todo: modify this to work with plexPlayer
let hasUIConfig = true; let hasUIConfig = true;
let canConvert = true; let canConvert = true;
if (lodash.isArray(this.config.entity)) { if (lodash.isArray(this.config.entity)) {

@ -56,6 +56,8 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
sections: Array<Record<string, any>> = []; sections: Array<Record<string, any>> = [];
clients: Record<string, any> = {};
entitiesRegistry: false | Array<Record<string, any>> = false; entitiesRegistry: false | Array<Record<string, any>> = false;
plexValidSection = document.createElement('div'); plexValidSection = document.createElement('div');
@ -157,15 +159,33 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
const entities: any = document.createElement('paper-listbox'); const entities: any = document.createElement('paper-listbox');
entities.appendChild(addDropdownItem('')); entities.appendChild(addDropdownItem(''));
const addedEntityStrings: Array<string> = [];
_.forEach(this.entitiesRegistry, entityRegistry => { _.forEach(this.entitiesRegistry, entityRegistry => {
if ( if (
_.isEqual(entityRegistry.platform, 'cast') || _.isEqual(entityRegistry.platform, 'cast') ||
_.isEqual(entityRegistry.platform, 'kodi') || _.isEqual(entityRegistry.platform, 'kodi') ||
_.isEqual(entityRegistry.platform, 'androidtv') _.isEqual(entityRegistry.platform, 'androidtv')
) { ) {
entities.appendChild(addDropdownItem(entityRegistry.entity_id)); const entityName = `${entityRegistry.platform} | ${entityRegistry.entity_id}`;
entities.appendChild(addDropdownItem(entityName));
addedEntityStrings.push(entityName);
} }
}); });
_.forEach(this.clients, value => {
const entityName = `plexPlayer | ${value.name} | ${value.address} | ${value.machineIdentifier}`;
entities.appendChild(addDropdownItem(entityName));
addedEntityStrings.push(entityName);
});
if (_.isArray(this.config.entity)) {
_.forEach(this.config.entity, value => {
if (!_.includes(addedEntityStrings, value)) {
entities.appendChild(addDropdownItem(value));
addedEntityStrings.push(value);
}
});
}
entities.slot = 'dropdown-content'; entities.slot = 'dropdown-content';
entitiesDropDown.label = 'Entity'; entitiesDropDown.label = 'Entity';
entitiesDropDown.value = selected; entitiesDropDown.value = selected;
@ -245,15 +265,14 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
this.appendChild(this.content); this.appendChild(this.content);
// todo: do verify better, do not query plex every time
this.sections = [];
this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.plexPort, this.config.token, this.plexProtocol, this.config.sort);
this.sections = await this.plex.getSections(); this.sections = await this.plex.getSections();
this.clients = await this.plex.getClients();
this.plexValidSection.style.display = 'none'; this.plexValidSection.style.display = 'none';
this.plexValidSection.innerHTML = ''; this.plexValidSection.innerHTML = '';
// todo: modify this to work with plexPlayer
let hasUIConfig = true; let hasUIConfig = true;
let canConvert = true; let canConvert = true;
if (_.isArray(this.config.entity)) { if (_.isArray(this.config.entity)) {

Loading…
Cancel
Save