Skip to content

Commit

Permalink
fix(DeviceEvents): Handle power_state/focus_state/volume events properly
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbo2002 committed Dec 29, 2023
1 parent 65cbc62 commit 48010f3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/lib/device-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ export default class NodePyATVDeviceEvents extends EventEmitter {
}

applyStateAndEmitEvents(newState: NodePyATVState): void {
Object.keys(this.state).forEach((key: string) => {
let keys = Object.keys(this.state);

if('power_state' in newState && newState.power_state) {
keys = ['power_state'];
}
if('focus_state' in newState && newState.focus_state) {
keys = ['focus_state'];
}

// Volume events don't hold the complete state…
// see https://github.com/sebbo2002/node-pyatv/pull/291
if('volume' in newState && newState.volume) {
keys = ['volume'];
}

keys.forEach((key: string) => {

// @ts-ignore
const oldValue = this.state[key];
Expand Down

0 comments on commit 48010f3

Please sign in to comment.