Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Add homebridge_media_player_switch (on_off, play_pause, play_stop) #183

Merged
merged 3 commits into from
Jul 19, 2017
Merged

Add homebridge_media_player_switch (on_off, play_pause, play_stop) #183

merged 3 commits into from
Jul 19, 2017

Conversation

azogue
Copy link
Member

@azogue azogue commented Jul 12, 2017

Introduction

The logic of behavior mode for the media_player switches is too rigid, and for many media player platforms, which implement multiple features (pause, turn_on/off, stop...), this makes theses switches not very useful, requiring extra switches to model the real needs.

Description

A new homebridge keyword homebridge_media_player_switch for customising the media players in HA is proposed, to specify the behaviour mode, between play_pause, on_off or play_stop options.

Also, the change state logic for media_player's is inverted. Instead of comparing with the on state, for media_players it should be 'different from the off state', because of the multiple 'active' options that normally a media player presents.

Example customize config in Home Assistant:

homeassistant:
  customize:
    media_player.kodi:
      homebridge_media_player_switch: on_off

This change fixes #171 and eliminates the need of extra variables.

@mention-bot
Copy link

@azogue, thanks for your PR! By analyzing the history of the files in this pull request, we identified @robbiet480, @maddox and @nunofgs to be potential reviewers.

},
getPowerState(callback) {
this.log(`fetching power state for: ${this.name}`);

this.client.fetchState(this.entity_id, (data) => {
if (data) {
const powerState = data.state === this.onState;
const powerState = data.state != this.offState;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '!==' and instead saw '!=' eqeqeq

@@ -56,14 +74,14 @@ function HomeAssistantMediaPlayer(log, data, client) {
HomeAssistantMediaPlayer.prototype = {
onEvent(oldState, newState) {
this.switchService.getCharacteristic(Characteristic.On)
.setValue(newState.state === this.onState, null, 'internal');
.setValue(newState.state != this.offState, null, 'internal');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected '!==' and instead saw '!=' eqeqeq

} else if ((this.supportedFeatures | SUPPORT_TURN_ON) === this.supportedFeatures &&
(this.supportedFeatures | SUPPORT_TURN_OFF) === this.supportedFeatures) {
}
else if (support_on_off) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_on_off' is not in camel case camelcase

this.onState = 'playing';
this.offState = 'idle';
this.onService = 'media_play';
this.offService = 'media_stop';
} else if ((this.supportedFeatures | SUPPORT_TURN_ON) === this.supportedFeatures &&
(this.supportedFeatures | SUPPORT_TURN_OFF) === this.supportedFeatures) {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing curly brace does not appear on the same line as the subsequent block brace-style

this.onState = 'playing';
this.offState = 'paused';
this.onService = 'media_play';
this.offService = 'media_pause';
} else if ((this.supportedFeatures | SUPPORT_STOP) === this.supportedFeatures) {
}
else if (support_stop) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_stop' is not in camel case camelcase

this.offState = 'off';
this.onService = 'turn_on';
this.offService = 'turn_off';
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing curly brace does not appear on the same line as the subsequent block brace-style

const support_on_off = ((this.supportedFeatures | SUPPORT_TURN_ON) === this.supportedFeatures &&
(this.supportedFeatures | SUPPORT_TURN_OFF) === this.supportedFeatures);

if (this.data && this.data.attributes && this.data.attributes.homebridge_media_player_switch === 'on_off' && support_on_off) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_on_off' is not in camel case camelcase

if ((this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures) {
const support_pause = (this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures;
const support_stop = (this.supportedFeatures | SUPPORT_STOP) === this.supportedFeatures;
const support_on_off = ((this.supportedFeatures | SUPPORT_TURN_ON) === this.supportedFeatures &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_on_off' is not in camel case camelcase

@@ -31,18 +31,36 @@ function HomeAssistantMediaPlayer(log, data, client) {
this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
}

if ((this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures) {
const support_pause = (this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures;
const support_stop = (this.supportedFeatures | SUPPORT_STOP) === this.supportedFeatures;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_stop' is not in camel case camelcase

@@ -31,18 +31,36 @@ function HomeAssistantMediaPlayer(log, data, client) {
this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
}

if ((this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures) {
const support_pause = (this.supportedFeatures | SUPPORT_PAUSE) === this.supportedFeatures;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier 'support_pause' is not in camel case camelcase

@robbiet480 robbiet480 merged commit ea7a15a into home-assistant:master Jul 19, 2017
@robbiet480
Copy link
Member

Thanks! 🐬 🍪 💯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Force power on/off with media player instead of play/pause?
5 participants