Add: Better check for config format of entities

pull/16/head
Juraj Nyíri 4 years ago
parent e0245f6a56
commit 95a83f2e2e

@ -17194,6 +17194,20 @@ var lodash = createCommonjsModule(function (module, exports) {
}.call(commonjsGlobal)); }.call(commonjsGlobal));
}); });
/* eslint-disable @typescript-eslint/no-explicit-any */
const CSS_STYLE = {
width: 138,
height: 203,
expandedWidth: 220,
expandedHeight: 324,
episodeWidth: 300,
episodeHeight: 169
};
const supported = {
kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode']
};
var bind = function bind(fn, thisArg) { var bind = function bind(fn, thisArg) {
return function wrap() { return function wrap() {
var args = new Array(arguments.length); var args = new Array(arguments.length);
@ -18698,10 +18712,7 @@ class Plex {
class PlayController { class PlayController {
constructor(hass, plex, entity) { constructor(hass, plex, entity) {
this.supported = { this.supported = supported;
kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode']
};
this.getState = async (entityID) => { this.getState = async (entityID) => {
return this.hass.callApi('GET', `states/${entityID}`); return this.hass.callApi('GET', `states/${entityID}`);
}; };
@ -18894,15 +18905,6 @@ const getOffset = (el) => {
return { top: y, left: x }; return { top: y, left: x };
}; };
const CSS_STYLE = {
width: 138,
height: 203,
expandedWidth: 220,
expandedHeight: 324,
episodeWidth: 300,
episodeHeight: 169
};
/** /**
* @license * @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
@ -20094,9 +20096,22 @@ class PlexMeetsHomeAssistant extends HTMLElement {
}; };
this.setConfig = (config) => { this.setConfig = (config) => {
this.plexProtocol = 'http'; this.plexProtocol = 'http';
if (!config.entity || config.entity.length === 0) { if (!config.entity || config.entity.length === 0 || !lodash.isObject(config.entity)) {
throw new Error('You need to define at least one entity'); throw new Error('You need to define at least one entity');
} }
if (lodash.isObject(config.entity)) {
let entityDefined = false;
// eslint-disable-next-line consistent-return
lodash.forEach(config.entity, (value, key) => {
if (supported[key]) {
entityDefined = true;
return false;
}
});
if (!entityDefined) {
throw new Error('You need to define at least one supported entity');
}
}
if (!config.token) { if (!config.token) {
throw new Error('You need to define a token'); throw new Error('You need to define a token');
} }

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
const CSS_STYLE = { const CSS_STYLE = {
width: 138, width: 138,
height: 203, height: 203,
@ -7,6 +8,11 @@ const CSS_STYLE = {
episodeHeight: 169 episodeHeight: 169
}; };
const supported: any = {
kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode']
};
const LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec semper risus vitae aliquet interdum. Nulla facilisi. Pellentesque viverra sagittis lorem eget aliquet. Cras vehicula, purus vel consectetur mattis, ipsum arcu ullamcorper mi, id viverra purus ex eu dolor. Integer vehicula lacinia sem convallis iaculis. Nulla fermentum erat interdum, efficitur felis in, mollis neque. Vivamus luctus metus eget nisl pellentesque, placerat elementum magna eleifend. const LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec semper risus vitae aliquet interdum. Nulla facilisi. Pellentesque viverra sagittis lorem eget aliquet. Cras vehicula, purus vel consectetur mattis, ipsum arcu ullamcorper mi, id viverra purus ex eu dolor. Integer vehicula lacinia sem convallis iaculis. Nulla fermentum erat interdum, efficitur felis in, mollis neque. Vivamus luctus metus eget nisl pellentesque, placerat elementum magna eleifend.
Curabitur tempor imperdiet felis, a vehicula augue tincidunt quis. Proin a libero vel ex ultrices commodo. Nam mattis, neque ac auctor pulvinar, augue ipsum ullamcorper magna, vel ultrices dolor purus in nisi. Ut et turpis varius, rhoncus sem quis, finibus quam. Nulla interdum lacus finibus, rhoncus magna non, semper erat. Nunc sit amet imperdiet ipsum. Vivamus purus velit, lobortis vitae consequat id, lobortis et nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis tellus et dictum ultricies. Duis commodo tellus sed augue cursus dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In blandit, tellus id tincidunt commodo, ante mauris sagittis mi, sit amet elementum nunc nulla eget diam. Aenean sed faucibus mauris. Aliquam eu ultricies orci, in consequat dui. Curabitur tempor imperdiet felis, a vehicula augue tincidunt quis. Proin a libero vel ex ultrices commodo. Nam mattis, neque ac auctor pulvinar, augue ipsum ullamcorper magna, vel ultrices dolor purus in nisi. Ut et turpis varius, rhoncus sem quis, finibus quam. Nulla interdum lacus finibus, rhoncus magna non, semper erat. Nunc sit amet imperdiet ipsum. Vivamus purus velit, lobortis vitae consequat id, lobortis et nunc. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis tellus et dictum ultricies. Duis commodo tellus sed augue cursus dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In blandit, tellus id tincidunt commodo, ante mauris sagittis mi, sit amet elementum nunc nulla eget diam. Aenean sed faucibus mauris. Aliquam eu ultricies orci, in consequat dui.
@ -17,4 +23,4 @@ Nam molestie auctor erat. Sed tempor porttitor nisi vel hendrerit. Vestibulum eg
Vivamus at enim hendrerit, lacinia mauris sit amet, facilisis dolor. Sed egestas urna ut ante iaculis consequat. Ut ac libero commodo, egestas ligula in, pretium nisi. Nullam dolor sapien, auctor vitae enim non, dapibus laoreet enim. Nullam rhoncus efficitur nibh faucibus ultricies. In vitae libero sed turpis posuere tincidunt. Vivamus dapibus erat placerat lorem fringilla, a varius elit placerat. Aliquam sodales condimentum porta. Etiam ac mattis dui, quis sodales urna. Praesent at laoreet lectus. Ut tellus nisl, ullamcorper vitae metus eget, porttitor sagittis metus. Aliquam purus dolor, porttitor eget magna a, ullamcorper aliquam dui. Donec a neque vel justo fringilla tincidunt maximus eget nisl. Aliquam consequat id turpis nec laoreet. In dignissim enim quis neque scelerisque finibus.`; Vivamus at enim hendrerit, lacinia mauris sit amet, facilisis dolor. Sed egestas urna ut ante iaculis consequat. Ut ac libero commodo, egestas ligula in, pretium nisi. Nullam dolor sapien, auctor vitae enim non, dapibus laoreet enim. Nullam rhoncus efficitur nibh faucibus ultricies. In vitae libero sed turpis posuere tincidunt. Vivamus dapibus erat placerat lorem fringilla, a varius elit placerat. Aliquam sodales condimentum porta. Etiam ac mattis dui, quis sodales urna. Praesent at laoreet lectus. Ut tellus nisl, ullamcorper vitae metus eget, porttitor sagittis metus. Aliquam purus dolor, porttitor eget magna a, ullamcorper aliquam dui. Donec a neque vel justo fringilla tincidunt maximus eget nisl. Aliquam consequat id turpis nec laoreet. In dignissim enim quis neque scelerisque finibus.`;
export { CSS_STYLE, LOREM_IPSUM }; export { CSS_STYLE, LOREM_IPSUM, supported };

@ -3,6 +3,7 @@
import { HomeAssistant } from 'custom-card-helpers'; import { HomeAssistant } from 'custom-card-helpers';
import _ from 'lodash'; import _ from 'lodash';
import Plex from './Plex'; import Plex from './Plex';
import { supported } from '../const';
class PlayController { class PlayController {
entity: Record<string, any>; entity: Record<string, any>;
@ -11,10 +12,7 @@ class PlayController {
plex: Plex; plex: Plex;
supported: any = { supported: any = supported;
kodi: ['movie', 'episode'],
androidtv: ['movie', 'show', 'season', 'episode']
};
constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>) { constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>) {
this.hass = hass; this.hass = hass;

@ -2,10 +2,10 @@
/* eslint-env browser */ /* eslint-env browser */
import { HomeAssistant } from 'custom-card-helpers'; import { HomeAssistant } from 'custom-card-helpers';
import _ from 'lodash'; import _ from 'lodash';
import { supported, CSS_STYLE } from './const';
import Plex from './modules/Plex'; import Plex from './modules/Plex';
import PlayController from './modules/PlayController'; import PlayController from './modules/PlayController';
import { escapeHtml, getOffset } from './modules/utils'; import { escapeHtml, getOffset } from './modules/utils';
import { CSS_STYLE } from './const';
import style from './modules/style'; import style from './modules/style';
class PlexMeetsHomeAssistant extends HTMLElement { class PlexMeetsHomeAssistant extends HTMLElement {
@ -780,9 +780,22 @@ class PlexMeetsHomeAssistant extends HTMLElement {
setConfig = (config: any): void => { setConfig = (config: any): void => {
this.plexProtocol = 'http'; this.plexProtocol = 'http';
if (!config.entity || config.entity.length === 0) { if (!config.entity || config.entity.length === 0 || !_.isObject(config.entity)) {
throw new Error('You need to define at least one entity'); throw new Error('You need to define at least one entity');
} }
if (_.isObject(config.entity)) {
let entityDefined = false;
// eslint-disable-next-line consistent-return
_.forEach(config.entity, (value, key) => {
if (supported[key]) {
entityDefined = true;
return false;
}
});
if (!entityDefined) {
throw new Error('You need to define at least one supported entity');
}
}
if (!config.token) { if (!config.token) {
throw new Error('You need to define a token'); throw new Error('You need to define a token');
} }

Loading…
Cancel
Save