-
-
Notifications
You must be signed in to change notification settings - Fork 142
Add homebridge_media_player_switch
(on_off, play_pause, play_stop)
#183
Conversation
… change state logic for media_player
@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. |
accessories/media_player.js
Outdated
}, | ||
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; |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
@@ -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'); |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
} else if ((this.supportedFeatures | SUPPORT_TURN_ON) === this.supportedFeatures && | ||
(this.supportedFeatures | SUPPORT_TURN_OFF) === this.supportedFeatures) { | ||
} | ||
else if (support_on_off) { |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
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) { | ||
} |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
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) { |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
this.offState = 'off'; | ||
this.onService = 'turn_on'; | ||
this.offService = 'turn_off'; | ||
} |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
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) { |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
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 && |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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
accessories/media_player.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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
Thanks! 🐬 🍪 💯 |
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, betweenplay_pause
,on_off
orplay_stop
options.Also, the change state logic for
media_player
's is inverted. Instead of comparing with theon
state, formedia_players
it should be 'different from theoff
state', because of the multiple 'active' options that normally a media player presents.Example customize config in Home Assistant:
This change fixes #171 and eliminates the need of extra variables.