Add: runBefore parameter

pull/16/head
Juraj Nyíri 4 years ago
parent 66ef70bdb1
commit 52c3ce67de

@ -18830,8 +18830,9 @@ class Plex {
} }
class PlayController { class PlayController {
constructor(hass, plex, entity) { constructor(hass, plex, entity, runBefore) {
this.plexPlayerEntity = ''; this.plexPlayerEntity = '';
this.runBefore = false;
this.supported = supported; this.supported = supported;
this.getState = async (entityID) => { this.getState = async (entityID) => {
return this.hass.callApi('GET', `states/${entityID}`); return this.hass.callApi('GET', `states/${entityID}`);
@ -18891,6 +18892,9 @@ class PlayController {
return foundResult; return foundResult;
}; };
this.play = async (data, instantPlay = false) => { this.play = async (data, instantPlay = false) => {
if (lodash.isArray(this.runBefore)) {
await this.hass.callService(this.runBefore[0], this.runBefore[1], {});
}
const entity = this.getPlayService(data); const entity = this.getPlayService(data);
switch (entity.key) { switch (entity.key) {
case 'kodi': case 'kodi':
@ -19053,13 +19057,6 @@ class PlayController {
}); });
return service; return service;
}; };
this.isPlexPlayerSupported = (entityName) => {
let found = false;
if (this.getPlexPlayerMachineIdentifier(entityName)) {
found = true;
}
return found;
};
this.getPlexPlayerMachineIdentifier = (entityName) => { this.getPlexPlayerMachineIdentifier = (entityName) => {
let machineIdentifier = ''; let machineIdentifier = '';
lodash.forEach(this.plex.clients, plexClient => { lodash.forEach(this.plex.clients, plexClient => {
@ -19077,30 +19074,44 @@ class PlayController {
this.isPlaySupported = (data) => { this.isPlaySupported = (data) => {
return !lodash.isEmpty(this.getPlayService(data)); return !lodash.isEmpty(this.getPlayService(data));
}; };
this.isPlexPlayerSupported = (entityName) => {
let found = false;
if (this.getPlexPlayerMachineIdentifier(entityName)) {
found = true;
}
return found || !lodash.isEqual(this.runBefore, false);
};
this.isKodiSupported = (entityName) => { this.isKodiSupported = (entityName) => {
if (entityName) { if (entityName) {
return (this.hass.states[entityName] && const hasKodiMediaSearchInstalled = this.hass.states['sensor.kodi_media_sensor_search'] &&
this.hass.states['sensor.kodi_media_sensor_search'] && this.hass.states['sensor.kodi_media_sensor_search'].state !== 'unavailable';
this.hass.states['sensor.kodi_media_sensor_search'].state !== 'unavailable' && return ((this.hass.states[entityName] &&
this.hass.states[entityName].state !== 'off' && this.hass.states[entityName].state !== 'off' &&
this.hass.states[entityName].state !== 'unavailable'); this.hass.states[entityName].state !== 'unavailable' &&
hasKodiMediaSearchInstalled) ||
(!lodash.isEqual(this.runBefore, false) && hasKodiMediaSearchInstalled));
} }
return false; return false;
}; };
this.isCastSupported = (entityName) => { this.isCastSupported = (entityName) => {
return (this.hass.states[entityName] && return ((this.hass.states[entityName] &&
!lodash.isNil(this.hass.states[entityName].attributes) && !lodash.isNil(this.hass.states[entityName].attributes) &&
this.hass.states[entityName].state !== 'unavailable'); this.hass.states[entityName].state !== 'unavailable') ||
!lodash.isEqual(this.runBefore, false));
}; };
this.isAndroidTVSupported = (entityName) => { this.isAndroidTVSupported = (entityName) => {
return (this.hass.states[entityName] && return ((this.hass.states[entityName] &&
!lodash.isEqual(this.hass.states[entityName].state, 'off') && !lodash.isEqual(this.hass.states[entityName].state, 'off') &&
this.hass.states[entityName].attributes && this.hass.states[entityName].attributes &&
this.hass.states[entityName].attributes.adb_response !== undefined); this.hass.states[entityName].attributes.adb_response !== undefined) ||
!lodash.isEqual(this.runBefore, false));
}; };
this.hass = hass; this.hass = hass;
this.plex = plex; this.plex = plex;
this.entity = entity; this.entity = entity;
if (!lodash.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.');
}
} }
} }
@ -19898,6 +19909,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
super(...arguments); super(...arguments);
this.plexProtocol = 'http'; this.plexProtocol = 'http';
this.detailsShown = false; this.detailsShown = false;
this.runBefore = '';
this.columnsCount = 0; this.columnsCount = 0;
this.renderedItems = 0; this.renderedItems = 0;
this.maxRenderCount = false; this.maxRenderCount = false;
@ -21018,6 +21030,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.maxCount) { if (config.maxCount) {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
if (config.runBefore) {
this.runBefore = config.runBefore;
}
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort);
}; };
this.getCardSize = () => { this.getCardSize = () => {
@ -21027,7 +21042,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
set hass(hass) { set hass(hass) {
this.hassObj = hass; this.hassObj = hass;
if (this.plex) { if (this.plex) {
this.playController = new PlayController(this.hassObj, this.plex, this.config.entity); this.playController = new PlayController(this.hassObj, this.plex, this.config.entity, this.runBefore);
} }
if (!this.content) { if (!this.content) {
this.error = ''; this.error = '';

@ -16,12 +16,17 @@ class PlayController {
plex: Plex; plex: Plex;
runBefore: Array<string> | false = false;
supported: any = supported; supported: any = supported;
constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>) { constructor(hass: HomeAssistant, plex: Plex, entity: Record<string, any>, runBefore: string) {
this.hass = hass; this.hass = hass;
this.plex = plex; this.plex = plex;
this.entity = entity; this.entity = entity;
if (!_.isEmpty(runBefore) && this.hass.states[runBefore]) {
this.runBefore = runBefore.split('.');
}
} }
private getState = async (entityID: string): Promise<Record<string, any>> => { private getState = async (entityID: string): Promise<Record<string, any>> => {
@ -86,6 +91,9 @@ class PlayController {
}; };
play = async (data: Record<string, any>, instantPlay = false): Promise<void> => { play = async (data: Record<string, any>, instantPlay = false): Promise<void> => {
if (_.isArray(this.runBefore)) {
await this.hass.callService(this.runBefore[0], this.runBefore[1], {});
}
const entity = this.getPlayService(data); const entity = this.getPlayService(data);
switch (entity.key) { switch (entity.key) {
case 'kodi': case 'kodi':
@ -268,14 +276,6 @@ class PlayController {
return service; return service;
}; };
isPlexPlayerSupported = (entityName: string): boolean => {
let found = false;
if (this.getPlexPlayerMachineIdentifier(entityName)) {
found = true;
}
return found;
};
private getPlexPlayerMachineIdentifier = (entityName: string): string => { private getPlexPlayerMachineIdentifier = (entityName: string): string => {
let machineIdentifier = ''; let machineIdentifier = '';
_.forEach(this.plex.clients, plexClient => { _.forEach(this.plex.clients, plexClient => {
@ -297,14 +297,25 @@ class PlayController {
return !_.isEmpty(this.getPlayService(data)); return !_.isEmpty(this.getPlayService(data));
}; };
private isPlexPlayerSupported = (entityName: string): boolean => {
let found = false;
if (this.getPlexPlayerMachineIdentifier(entityName)) {
found = true;
}
return found || !_.isEqual(this.runBefore, false);
};
private isKodiSupported = (entityName: string): boolean => { private isKodiSupported = (entityName: string): boolean => {
if (entityName) { if (entityName) {
return ( const hasKodiMediaSearchInstalled =
this.hass.states[entityName] &&
this.hass.states['sensor.kodi_media_sensor_search'] && this.hass.states['sensor.kodi_media_sensor_search'] &&
this.hass.states['sensor.kodi_media_sensor_search'].state !== 'unavailable' && this.hass.states['sensor.kodi_media_sensor_search'].state !== 'unavailable';
return (
(this.hass.states[entityName] &&
this.hass.states[entityName].state !== 'off' && this.hass.states[entityName].state !== 'off' &&
this.hass.states[entityName].state !== 'unavailable' this.hass.states[entityName].state !== 'unavailable' &&
hasKodiMediaSearchInstalled) ||
(!_.isEqual(this.runBefore, false) && hasKodiMediaSearchInstalled)
); );
} }
return false; return false;
@ -312,18 +323,20 @@ class PlayController {
private isCastSupported = (entityName: string): boolean => { private isCastSupported = (entityName: string): boolean => {
return ( return (
this.hass.states[entityName] && (this.hass.states[entityName] &&
!_.isNil(this.hass.states[entityName].attributes) && !_.isNil(this.hass.states[entityName].attributes) &&
this.hass.states[entityName].state !== 'unavailable' this.hass.states[entityName].state !== 'unavailable') ||
!_.isEqual(this.runBefore, false)
); );
}; };
private isAndroidTVSupported = (entityName: string): boolean => { private isAndroidTVSupported = (entityName: string): boolean => {
return ( return (
this.hass.states[entityName] && (this.hass.states[entityName] &&
!_.isEqual(this.hass.states[entityName].state, 'off') && !_.isEqual(this.hass.states[entityName].state, 'off') &&
this.hass.states[entityName].attributes && this.hass.states[entityName].attributes &&
this.hass.states[entityName].attributes.adb_response !== undefined this.hass.states[entityName].attributes.adb_response !== undefined) ||
!_.isEqual(this.runBefore, false)
); );
}; };
} }

@ -23,6 +23,8 @@ class PlexMeetsHomeAssistant extends HTMLElement {
detailsShown = false; detailsShown = false;
runBefore = '';
renderNewElementsIfNeededTimeout: any; renderNewElementsIfNeededTimeout: any;
columnsCount = 0; columnsCount = 0;
@ -106,7 +108,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
set hass(hass: HomeAssistant) { set hass(hass: HomeAssistant) {
this.hassObj = hass; this.hassObj = hass;
if (this.plex) { if (this.plex) {
this.playController = new PlayController(this.hassObj, this.plex, this.config.entity); this.playController = new PlayController(this.hassObj, this.plex, this.config.entity, this.runBefore);
} }
if (!this.content) { if (!this.content) {
@ -1341,6 +1343,9 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (config.maxCount) { if (config.maxCount) {
this.maxCount = config.maxCount; this.maxCount = config.maxCount;
} }
if (config.runBefore) {
this.runBefore = config.runBefore;
}
this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort); this.plex = new Plex(this.config.ip, this.config.port, this.config.token, this.plexProtocol, this.config.sort);
}; };

Loading…
Cancel
Save