home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.75k stars 30.86k forks source link

MediaPlayer Resolving State With Wrong Service Calls #432

Closed maddox closed 9 years ago

maddox commented 9 years ago

In testing my Good Night scene, I noticed that my media player was not actually getting paused.

  - name: Good Night
    entities:
      media_player.itunes: paused
      media_player.kitchen_music_airtunes_speaker: on
      media_player.family_room_airtunes_speaker: off
      media_player.deck_airtunes_speaker: off
      media_player.kitchen_airtunes_speaker: off
      media_player.bedroom_airtunes_speaker: off
      media_player.office_airtunes_speaker: off
      switch.kitchen_tv: off
      switch.family_room_tv: off
      light.living_room_left: off
      light.living_room_right: off
      light.living_room_lamp: off
      light.family_room_left: off
      light.family_room_right: off
      light.family_room_lamp: off
      light.family_room_window:
        state: on
        brightness: 50

With some digging around I found this error:

15-09-22 21:42:29 WARNING (Thread-20) [homeassistant.helpers.state] reproduce_state: Unable to reproduce state <state media_player.itunes=paused @ 21:38:11 22-09-2015>

With more digging, I found this:

15-09-22 21:48:37 INFO (Thread-34) [homeassistant.core] Bus:Handling <Event call_service[L]: service=media_play_pause, domain=media_player, service_call_id=4507326728-21, entity_id=media_player.itunes>

Specifically this part: service=media_play_pause

The iTunes media player does not implement the play_pause method, so this is failing. More importantly, it shouldn't be calling this service. It should be calling the discrete methods for play and pause, rather than the toggle.

I did some spelunking, but couldn't really figure out where it was making the decision to use this service call.

balloob commented 9 years ago

Right now the scene component only supports the ON and OFF states (source). That service call should have been triggered by something else (automation perhaps?).

We could make this method more smart and base decisions what services to call based on the domain of the entity and the state it wants to achieve.

Something like:

if state.domain == 'media_player' and state == 'paused':
  service = 'media_pause'
elif …
maddox commented 9 years ago

I don't understand. So we can't set the state of things to anything but on or offin a scene?

Let me go though this again with a more confident isolation and see if i still see that service call in the logs.

maddox commented 9 years ago

OK, you were right. It must have been a stray call in the logs. So the only issue seems to be the:

15-09-22 21:42:29 WARNING (Thread-20) [homeassistant.helpers.state] reproduce_state: Unable to reproduce state <state media_player.itunes=paused @ 21:38:11 22-09-2015>

...due to the fact that it's asking for a state that isn't supported. This is sort of unfortunate :(

maddox commented 9 years ago

Closing this.