pull/16/head
Juraj Nyíri 4 years ago
parent 458237be3b
commit d123fdb3cf

File diff suppressed because it is too large Load Diff

9
package-lock.json generated

@ -1965,6 +1965,15 @@
}
}
},
"rollup-plugin-json": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/rollup-plugin-json/-/rollup-plugin-json-2.3.1.tgz",
"integrity": "sha512-alQQQVPo2z9pl6LSK8QqyDlWwCH5KeE8YxgQv7fa/SeTxz+gQe36jBjcha7hQW68MrVh9Ms71EQaMZDAG3w2yw==",
"dev": true,
"requires": {
"rollup-pluginutils": "^2.0.1"
}
},
"rollup-plugin-node-resolve": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz",

@ -44,6 +44,7 @@
"rollup": "^2.23.1",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-json": "2.3",
"rollup-plugin-terser": "^7.0.0",
"rollup-plugin-typescript2": "^0.27.2"
}

@ -6,7 +6,13 @@ import json from '@rollup/plugin-json';
const dev = process.env.ROLLUP_WATCH;
const plugins = [nodeResolve({}), commonjs(), typescript(), json(), !dev && terser()];
const plugins = [
nodeResolve({ jsnext: true, preferBuiltins: true, browser: true }),
commonjs(),
typescript(),
json(),
!dev && terser()
];
export default [
{

@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import axios from 'axios';
class Plex {
ip: string;
port: number;
token: string;
protocol: string;
constructor(ip: string, port = 32400, token: string, protocol: 'http' | 'https' = 'http') {
this.ip = ip;
this.port = port;
this.token = token;
this.protocol = protocol;
}
getServerInfo = async (): Promise<any> => {
const url = `${this.protocol}://${this.ip}:${this.port}/?X-Plex-Token=${this.token}`;
return (await axios.get(url)).data.MediaContainer;
};
getSections = async (): Promise<any> => {
const url = `${this.protocol}://${this.ip}:${this.port}/library/sections?X-Plex-Token=${this.token}`;
return (await axios.get(url)).data.MediaContainer.Directory;
};
}
export default Plex;

@ -3,6 +3,7 @@
/* eslint-env browser */
import { HomeAssistant, LovelaceCardEditor } from 'custom-card-helpers';
import _ from 'lodash';
import Plex from './modules/Plex';
import { escapeHtml } from './utils';
class PlexMeetsHomeAssistant extends HTMLElement {
@ -14,7 +15,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
expandedHeight = 324;
plexProtocol = '';
plexProtocol: 'http' | 'https' = 'http';
movieElems: any = [];
@ -148,16 +149,17 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.renderPage(hass);
};
loadInitialData = (hass: HomeAssistant): void => {
loadInitialData = async (hass: HomeAssistant): Promise<void> => {
const plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol);
const [plexInfo, plexSections] = await Promise.all([plex.getServerInfo(), plex.getSections()]);
console.log(plexInfo);
console.log(plexSections);
this.loading = true;
this.renderPage(hass);
const serverRequest = this.getData(
`${this.plexProtocol}://${this.config.ip}:${this.config.port}/?X-Plex-Token=${this.config.token}`
);
const sectionsRequest = this.getData(
`${this.plexProtocol}://${this.config.ip}:${this.config.port}/library/sections?X-Plex-Token=${this.config.token}`
);
/*
const parser = new DOMParser();
const sectionsDetails: Array<any> = [];
Promise.all([serverRequest, sectionsRequest])
@ -230,6 +232,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
this.error = `Plex server did not respond within ${this.requestTimeout / 1000} seconds.`;
this.renderPage(hass);
});
*/
};
// todo: run also on resize

Loading…
Cancel
Save