Fix: Properly rename adb to androidtv

pull/16/head
Juraj Nyíri 4 years ago
parent 68bc8985e6
commit e93cf6172e

@ -30,7 +30,7 @@ Custom integration which integrates plex into Home Assistant and makes it possib
**entity**: You need to configure at least one supported media_player entity. **entity**: You need to configure at least one supported media_player entity.
- **adb**: Entity id of your media_player configured via [Android TV](https://www.home-assistant.io/integrations/androidtv/) - **androidtv**: Entity id of your media_player configured via [Android TV](https://www.home-assistant.io/integrations/androidtv/)
- **kodi**: Entity id of your media_player configured via [Kodi](https://www.home-assistant.io/integrations/kodi/). - **kodi**: Entity id of your media_player configured via [Kodi](https://www.home-assistant.io/integrations/kodi/).
You also need to install and configure integration [Kodi Recently Added Media](https://github.com/jtbgroup/kodi-media-sensors) and its sensor **kodi_media_sensor_search**. You also need to install and configure integration [Kodi Recently Added Media](https://github.com/jtbgroup/kodi-media-sensors) and its sensor **kodi_media_sensor_search**.
@ -39,7 +39,7 @@ Custom integration which integrates plex into Home Assistant and makes it possib
_You can combine multiple supported entities_, in that case, entity for supported content will be chosen in order how you entered them. _You can combine multiple supported entities_, in that case, entity for supported content will be chosen in order how you entered them.
As an example, if content can be played / shown both by kodi and adb, and you entered kodi first, it will be shown by kodi. If it cannot be played by kodi but can be played by adb, adb will be used. As an example, if content can be played / shown both by kodi and androidtv, and you entered kodi first, it will be shown by kodi. If it cannot be played by kodi but can be played by androidtv, androidtv will be used.
This will also work with play button being shown, it will only show when you can actually play content on your device. This will also work with play button being shown, it will only show when you can actually play content on your device.

@ -18736,8 +18736,8 @@ class PlayController {
case 'kodi': case 'kodi':
await this.playViaKodi(data.title, data.type); await this.playViaKodi(data.title, data.type);
break; break;
case 'adb': case 'androidtv':
await this.playViaADB(data.key.split('/')[3], instantPlay); await this.playViaAndroidTV(data.key.split('/')[3], instantPlay);
break; break;
default: default:
throw Error(`No service available to play ${data.title}!`); throw Error(`No service available to play ${data.title}!`);
@ -18763,7 +18763,7 @@ class PlayController {
throw Error(`Plex type ${type} is not supported in Kodi.`); throw Error(`Plex type ${type} is not supported in Kodi.`);
} }
}; };
this.playViaADB = async (mediaID, instantPlay = false) => { this.playViaAndroidTV = async (mediaID, instantPlay = false) => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
let command = `am start`; let command = `am start`;
if (instantPlay) { if (instantPlay) {
@ -18772,12 +18772,12 @@ class PlayController {
command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`; command += ` -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`;
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity.adb, entity_id: this.entity.androidtv,
command: 'HOME' command: 'HOME'
}); });
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity.adb, entity_id: this.entity.androidtv,
command command
}); });
}; };
@ -18785,7 +18785,7 @@ class PlayController {
let service = ''; let service = '';
lodash.forEach(this.entity, (value, key) => { lodash.forEach(this.entity, (value, key) => {
if (lodash.includes(this.supported[key], data.type)) { if (lodash.includes(this.supported[key], data.type)) {
if ((key === 'kodi' && this.isKodiSupported()) || (key === 'adb' && this.isADBSupported())) { if ((key === 'kodi' && this.isKodiSupported()) || (key === 'androidtv' && this.isAndroidTVSupported())) {
service = key; service = key;
return false; return false;
} }
@ -18807,10 +18807,10 @@ class PlayController {
} }
return false; return false;
}; };
this.isADBSupported = () => { this.isAndroidTVSupported = () => {
return (this.hass.states[this.entity.adb] && return (this.hass.states[this.entity.androidtv] &&
this.hass.states[this.entity.adb].attributes && this.hass.states[this.entity.androidtv].attributes &&
this.hass.states[this.entity.adb].attributes.adb_response !== undefined); this.hass.states[this.entity.androidtv].attributes.adb_response !== undefined);
}; };
this.hass = hass; this.hass = hass;
this.plex = plex; this.plex = plex;

@ -59,8 +59,8 @@ class PlayController {
case 'kodi': case 'kodi':
await this.playViaKodi(data.title, data.type); await this.playViaKodi(data.title, data.type);
break; break;
case 'adb': case 'androidtv':
await this.playViaADB(data.key.split('/')[3], instantPlay); await this.playViaAndroidTV(data.key.split('/')[3], instantPlay);
break; break;
default: default:
throw Error(`No service available to play ${data.title}!`); throw Error(`No service available to play ${data.title}!`);
@ -86,7 +86,7 @@ class PlayController {
} }
}; };
private playViaADB = async (mediaID: number, instantPlay = false): Promise<void> => { private playViaAndroidTV = async (mediaID: number, instantPlay = false): Promise<void> => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
let command = `am start`; let command = `am start`;
@ -98,12 +98,12 @@ class PlayController {
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity.adb, entity_id: this.entity.androidtv,
command: 'HOME' command: 'HOME'
}); });
this.hass.callService('androidtv', 'adb_command', { this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity.adb, entity_id: this.entity.androidtv,
command command
}); });
}; };
@ -112,7 +112,7 @@ class PlayController {
let service = ''; let service = '';
_.forEach(this.entity, (value, key) => { _.forEach(this.entity, (value, key) => {
if (_.includes(this.supported[key], data.type)) { if (_.includes(this.supported[key], data.type)) {
if ((key === 'kodi' && this.isKodiSupported()) || (key === 'adb' && this.isADBSupported())) { if ((key === 'kodi' && this.isKodiSupported()) || (key === 'androidtv' && this.isAndroidTVSupported())) {
service = key; service = key;
return false; return false;
} }
@ -139,11 +139,11 @@ class PlayController {
return false; return false;
}; };
private isADBSupported = (): boolean => { private isAndroidTVSupported = (): boolean => {
return ( return (
this.hass.states[this.entity.adb] && this.hass.states[this.entity.androidtv] &&
this.hass.states[this.entity.adb].attributes && this.hass.states[this.entity.androidtv].attributes &&
this.hass.states[this.entity.adb].attributes.adb_response !== undefined this.hass.states[this.entity.androidtv].attributes.adb_response !== undefined
); );
}; };
} }

Loading…
Cancel
Save