|
|
@ -19455,6 +19455,9 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
|
|
|
|
this.tabs = document.createElement('paper-tabs');
|
|
|
|
this.tabs = document.createElement('paper-tabs');
|
|
|
|
this.devicesTabs = 0;
|
|
|
|
this.devicesTabs = 0;
|
|
|
|
this.entities = [];
|
|
|
|
this.entities = [];
|
|
|
|
|
|
|
|
this.sections = [];
|
|
|
|
|
|
|
|
this.entitiesRegistry = false;
|
|
|
|
|
|
|
|
this.plexValidSection = document.createElement('div');
|
|
|
|
this.fireEvent = (node, type, detail, options = {}) => {
|
|
|
|
this.fireEvent = (node, type, detail, options = {}) => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
detail = detail === null || detail === undefined ? {} : detail;
|
|
|
|
detail = detail === null || detail === undefined ? {} : detail;
|
|
|
@ -19473,10 +19476,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;
|
|
|
|
this.config.entity = [];
|
|
|
|
if (!lodash.isEmpty(this.entities)) {
|
|
|
|
lodash.forEach(this.entities, entity => {
|
|
|
|
this.config.entity = [];
|
|
|
|
this.config.entity.push(entity.value);
|
|
|
|
lodash.forEach(this.entities, entity => {
|
|
|
|
});
|
|
|
|
this.config.entity.push(entity.value);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
this.fireEvent(this, 'config-changed', { config: this.config });
|
|
|
|
this.fireEvent(this, 'config-changed', { config: this.config });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -19486,31 +19491,33 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
|
|
|
|
libraryItem.innerHTML = text;
|
|
|
|
libraryItem.innerHTML = text;
|
|
|
|
return libraryItem;
|
|
|
|
return libraryItem;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const createEntitiesDropdown = (entitiesRegistry, selected, changeHandler) => {
|
|
|
|
const createEntitiesDropdown = (selected, changeHandler) => {
|
|
|
|
const entitiesDropDown = document.createElement('paper-dropdown-menu');
|
|
|
|
if (this.entitiesRegistry) {
|
|
|
|
const entities = document.createElement('paper-listbox');
|
|
|
|
const entitiesDropDown = document.createElement('paper-dropdown-menu');
|
|
|
|
lodash.forEach(entitiesRegistry, entityRegistry => {
|
|
|
|
const entities = document.createElement('paper-listbox');
|
|
|
|
if (lodash.isEqual(entityRegistry.platform, 'cast') ||
|
|
|
|
lodash.forEach(this.entitiesRegistry, entityRegistry => {
|
|
|
|
lodash.isEqual(entityRegistry.platform, 'kodi') ||
|
|
|
|
if (lodash.isEqual(entityRegistry.platform, 'cast') ||
|
|
|
|
lodash.isEqual(entityRegistry.platform, 'androidtv')) {
|
|
|
|
lodash.isEqual(entityRegistry.platform, 'kodi') ||
|
|
|
|
entities.appendChild(addDropdownItem(entityRegistry.entity_id));
|
|
|
|
lodash.isEqual(entityRegistry.platform, 'androidtv')) {
|
|
|
|
}
|
|
|
|
entities.appendChild(addDropdownItem(entityRegistry.entity_id));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
entities.slot = 'dropdown-content';
|
|
|
|
});
|
|
|
|
entitiesDropDown.label = 'Entity';
|
|
|
|
entities.slot = 'dropdown-content';
|
|
|
|
entitiesDropDown.value = selected;
|
|
|
|
entitiesDropDown.label = 'Entity';
|
|
|
|
entitiesDropDown.appendChild(entities);
|
|
|
|
entitiesDropDown.value = selected;
|
|
|
|
entitiesDropDown.style.width = '100%';
|
|
|
|
entitiesDropDown.appendChild(entities);
|
|
|
|
entitiesDropDown.className = 'entitiesDropDown';
|
|
|
|
entitiesDropDown.style.width = '100%';
|
|
|
|
entitiesDropDown.addEventListener('value-changed', changeHandler);
|
|
|
|
entitiesDropDown.className = 'entitiesDropDown';
|
|
|
|
this.entities.push(entitiesDropDown);
|
|
|
|
entitiesDropDown.addEventListener('value-changed', changeHandler);
|
|
|
|
return entitiesDropDown;
|
|
|
|
this.entities.push(entitiesDropDown);
|
|
|
|
|
|
|
|
return entitiesDropDown;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (this.content)
|
|
|
|
if (this.content)
|
|
|
|
this.content.remove();
|
|
|
|
this.content.remove();
|
|
|
|
let entitiesRegistry = false;
|
|
|
|
if (this.hassObj && !this.entitiesRegistry) {
|
|
|
|
if (this.hassObj) {
|
|
|
|
this.entitiesRegistry = await fetchEntityRegistry(this.hassObj.connection);
|
|
|
|
entitiesRegistry = await fetchEntityRegistry(this.hassObj.connection);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.entities = [];
|
|
|
|
this.entities = [];
|
|
|
|
this.content = document.createElement('div');
|
|
|
|
this.content = document.createElement('div');
|
|
|
@ -19545,6 +19552,18 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
|
|
|
|
this.libraryName.style.width = '100%';
|
|
|
|
this.libraryName.style.width = '100%';
|
|
|
|
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);
|
|
|
|
|
|
|
|
// todo: do verify better, do not query plex every time
|
|
|
|
|
|
|
|
this.sections = [];
|
|
|
|
|
|
|
|
if (this.plex) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
this.sections = await this.plex.getSections();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
// pass
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.plexValidSection.style.display = 'none';
|
|
|
|
const devicesTitle = document.createElement('h2');
|
|
|
|
const devicesTitle = document.createElement('h2');
|
|
|
|
devicesTitle.innerHTML = `Devices Configuration`;
|
|
|
|
devicesTitle.innerHTML = `Devices Configuration`;
|
|
|
|
devicesTitle.style.lineHeight = '29px';
|
|
|
|
devicesTitle.style.lineHeight = '29px';
|
|
|
@ -19556,40 +19575,33 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement {
|
|
|
|
addDeviceButton.style.cursor = 'pointer';
|
|
|
|
addDeviceButton.style.cursor = 'pointer';
|
|
|
|
addDeviceButton.innerHTML = '+';
|
|
|
|
addDeviceButton.innerHTML = '+';
|
|
|
|
addDeviceButton.addEventListener('click', () => {
|
|
|
|
addDeviceButton.addEventListener('click', () => {
|
|
|
|
if (entitiesRegistry) {
|
|
|
|
const entitiesDropdown = createEntitiesDropdown('', this.valueUpdated);
|
|
|
|
this.content.appendChild(createEntitiesDropdown(entitiesRegistry, '', this.valueUpdated));
|
|
|
|
if (entitiesDropdown) {
|
|
|
|
this.scrollTop = this.scrollHeight - this.clientHeight;
|
|
|
|
this.content.appendChild(entitiesDropdown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
devicesTitle.appendChild(addDeviceButton);
|
|
|
|
devicesTitle.appendChild(addDeviceButton);
|
|
|
|
this.content.appendChild(devicesTitle);
|
|
|
|
this.plexValidSection.innerHTML = '';
|
|
|
|
|
|
|
|
this.plexValidSection.appendChild(devicesTitle);
|
|
|
|
if (lodash.isString(this.config.entity)) {
|
|
|
|
if (lodash.isString(this.config.entity)) {
|
|
|
|
this.config.entity = [this.config.entity];
|
|
|
|
this.config.entity = [this.config.entity];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lodash.isArray(this.config.entity)) {
|
|
|
|
if (lodash.isArray(this.config.entity)) {
|
|
|
|
lodash.forEach(this.config.entity, entity => {
|
|
|
|
lodash.forEach(this.config.entity, entity => {
|
|
|
|
if (entitiesRegistry && lodash.isString(entity)) {
|
|
|
|
if (lodash.isString(entity)) ;
|
|
|
|
this.content.appendChild(createEntitiesDropdown(entitiesRegistry, entity, this.valueUpdated));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.appendChild(this.content);
|
|
|
|
if (!lodash.isEmpty(this.sections)) {
|
|
|
|
if (this.plex) {
|
|
|
|
lodash.forEach(this.sections, (section) => {
|
|
|
|
try {
|
|
|
|
libraryItems.appendChild(addDropdownItem(section.title));
|
|
|
|
const sections = await this.plex.getSections();
|
|
|
|
});
|
|
|
|
lodash.forEach(sections, (section) => {
|
|
|
|
this.libraryName.disabled = false;
|
|
|
|
libraryItems.appendChild(addDropdownItem(section.title));
|
|
|
|
this.libraryName.value = this.config.libraryName;
|
|
|
|
});
|
|
|
|
this.plexValidSection.style.display = 'block';
|
|
|
|
this.libraryName.disabled = false;
|
|
|
|
|
|
|
|
this.libraryName.value = this.config.libraryName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
|
|
|
// pass
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.content.appendChild(this.plexValidSection);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
this.setConfig = (config) => {
|
|
|
|
this.setConfig = (config) => {
|
|
|
|
console.log(config);
|
|
|
|
|
|
|
|
this.config = JSON.parse(JSON.stringify(config));
|
|
|
|
this.config = JSON.parse(JSON.stringify(config));
|
|
|
|
if (config.port) {
|
|
|
|
if (config.port) {
|
|
|
|
this.plexPort = config.port;
|
|
|
|
this.plexPort = config.port;
|
|
|
|