dahlb / ha_hatch

Home Assistant Integration for Hatch Rest Mini
MIT License
76 stars 16 forks source link

Trying to activate media player on Rest+ Gen2 shows Failed to Call Service #95

Closed spike-rogers closed 1 week ago

spike-rogers commented 4 months ago

Trying to activate the play button for media is showing "Failed to call service media_player/media_play. list index out of range.

I'm trying to activate any sound from the device.

vans113 commented 1 month ago

@dacmcbibs Funny thing. I did reboot earlier after the new install from hacs. Tried another reboot of HA and it came right up... go figure. My little one is asleep already so I will do some testing tomorrow and report back. Thanks all !

vans113 commented 1 month ago

I did some testing today. I've noticed sometimes the media play shows a " unknown " state when I load this mod up. If i start the sounds in the app then I can go to HA and have control to stop and start again. I also had an issue with the clock switch. I've attached a debug log.

2024-04-11 17:28:08.602 DEBUG (SyncWorker_40) [custom_components.ha_hatch_ChrisCarini_MOD.riot_clock_entity] args:{} 2024-04-11 17:28:08.605 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139828939056832] unsupported operand type(s) for |: 'NoneType' and 'int' Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/light/init.py", line 631, in async_handle_light_on_service await light.async_turn_on(filter_turn_on_params(light, params)) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1655, in async_turn_on await self.hass.async_add_executor_job(ft.partial(self.turn_on, kwargs)) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ha_hatch_ChrisCarini_MOD/riot_clock_entity.py", line 42, in turn_on self.rest_device.set_clock(brightness) File "/usr/local/lib/python3.12/site-packages/hatch_rest_api/riot.py", line 171, in set_clock "flags": self.flags | RIOT_FLAGS_CLOCK_ON,


TypeError: unsupported operand type(s) for |: 'NoneType' and 'int'
2024-04-11 17:28:10.197 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139828939056832] unsupported operand type(s) for ^: 'NoneType' and 'int'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2543, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2580, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 971, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1043, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 642, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1663, in async_turn_off
    await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha_hatch_ChrisCarini_MOD/riot_clock_entity.py", line 45, in turn_off
    self.rest_device.turn_clock_off()
  File "/usr/local/lib/python3.12/site-packages/hatch_rest_api/riot.py", line 179, in turn_clock_off
    self._update({"clock": {"flags": self.flags ^ RIOT_FLAGS_CLOCK_ON, "i": 655}})
                                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
travmo commented 1 month ago

I wanted to add to what @vans113 noticed, I also have been seeing Media Player set to Unknown. I have two of the Hatch Rest+ 2nd gen and they both show the same issue. I'd be glad to share any logging needed, just unsure how (if you need it)

yuejon commented 3 weeks ago

@ChrisCarini - I've gotten a little impatient waiting for @dahlb to merge your changes. Not sure if he's abandoned the integration or perhaps just really tied up with his little one. Anyway, I followed your instructions and installed your version of the integration. Unfortunately, I get the following error after logging in with my credentials:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ha_hatch_ChrisCarini_MOD/__init__.py", line 109, in async_setup_entry await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1860, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() [Previous line repeated 2 more times] File "/usr/src/homeassistant/homeassistant/loader.py", line 1133, in async_get_platforms platforms.update(self._load_platforms(platform_names)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1060, in _load_platforms platform_name: self._load_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1232, in _load_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1264, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 995, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/config/custom_components/ha_hatch_ChrisCarini_MOD/media_player.py", line 15, in <module> from .rest_media_entity import RestMediaEntity File "/config/custom_components/ha_hatch_ChrisCarini_MOD/rest_media_entity.py", line 18, in <module> from hatch_rest_api import ( ImportError: cannot import name 'RIoTAudioTrack' from 'hatch_rest_api' (/usr/local/lib/python3.12/site-packages/hatch_rest_api/__init__.py)

I'm running HA via Docker.

dahlb commented 3 weeks ago

@yuejon no need to ping me in your comment about timelines, I believe this feature is still waiting for code updates before it is ready to review again.

dacmcbibs commented 3 weeks ago

@yuejon - Taking a shot in the dark here based on your error...

My suggestion would be to shut the docker container down completely and start it again. I suspect this will force the hatch_rest_api update and you'll be good to go from there.

Give it a shot and let us know if this helped.

yuejon commented 3 weeks ago

@dacmcbibs - Thanks for the suggestion. I tried a full restart of the docker container and also rebuilding it but I'm still getting the same error.

dacmcbibs commented 3 weeks ago

@yuejon - can you validate that you have version 1.24 of the hatch_rest_api in your docker container?

yuejon commented 3 weeks ago

I have no idea how to do that. I have the docker container running on a Synology NAS and can dig around but no idea where the path to the hatch_rest_api would be. I started with custom_components but it doesn't appear to be there.

themajesticking commented 3 weeks ago

Just wanted to chime in and say that with ChrisCarini's version I'm getting the below error after logging in. The integration never starts successfully.

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ha_hatch_ChrisCarini_MOD/init.py", line 109, in async_setup_entry await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1860, in async_forward_entry_setups await integration.async_get_platforms(platforms) File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() File "/usr/src/homeassistant/homeassistant/loader.py", line 1145, in async_get_platforms import_future.result() [Previous line repeated 2 more times] File "/usr/src/homeassistant/homeassistant/loader.py", line 1133, in async_get_platforms platforms.update(self._load_platforms(platform_names)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1060, in _load_platforms platform_name: self._load_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1232, in _load_platform cache[full_name] = self._import_platform(platform_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/loader.py", line 1264, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "/config/custom_components/ha_hatch_ChrisCarini_MOD/media_player.py", line 15, in from .rest_media_entity import RestMediaEntity File "/config/custom_components/ha_hatch_ChrisCarini_MOD/rest_media_entity.py", line 18, in from hatch_rest_api import ( ImportError: cannot import name 'RIoTAudioTrack' from 'hatch_rest_api' (/usr/local/lib/python3.12/site-packages/hatch_rest_api/init.py)

yuejon commented 3 weeks ago

I tried redownloading the original hatch integration and the modified one too but that did not seem to force the update of hatch_rest_api... any suggestions on how to force the api download?

dahlb commented 1 week ago

this should all be working in version 1.18.0 sound mode allows you to pick which sound is playing and reflects the currently playing sound use select source to activate favorites, ie:

service: media_player.select_source
target:
  entity_id: media_player.sage_reading_light_media_player
data:
  source: Sleep

list of favorites are available on media player entity, ie:

sources:
  - Sleep-71564417
  - Kid Routine-71563479
  - Reading-71563479

select_source can be passed the favorite's name, or id, or first step's name, or the full name-id as available in sources list of entity

dbolton commented 1 week ago

I just updated to v1.19.0 then restarted home assistant but still getting the original error when pressing play:

Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:239 integration: Home Assistant WebSocket API (documentation, issues) First occurred: 10:19:57 PM (7 occurrences) Last logged: 10:22:09 PM

[139826159724352] Unexpected exception Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 239, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/media_player/init.py", line 817, in async_media_play await self.hass.async_add_executor_job(self.media_play) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/ha_hatch/riot_media_entity.py", line 67, in media_play self.rest_device.set_favorite(self._attr_sound_mode_list[0]) File "/usr/local/lib/python3.12/site-packages/hatch_rest_api/riot.py", line 197, in set_favorite fav_id = int(favorite_name_id.rsplit("-", 1)[1])


IndexError: list index out of range
ChrisCarini commented 1 week ago

Also just updated to 1.19.0 and getting the below error.

⚠️ Note: The media player entity is no longer working at all (it shows as unavailable, with no state or anything; likely because of the error below.

Error (seen 2x after updating and re-init-ing the component)

2024-05-08 01:47:13.591 ERROR (MainThread) [homeassistant.components.media_player] Error adding entity media_player.my_rest_media_player for domain media_player with platform ha_hatch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 580, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 892, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1358, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/ha_hatch/rest_entity.py", line 52, in async_added_to_hass
    self._update_local_state()
  File "/config/custom_components/ha_hatch/riot_media_entity.py", line 56, in _update_local_state
    self._attr_extra_state_attributes["current_favorite"] = self.rest_device.current_id
                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'RestIot' object has no attribute 'current_id'
ChrisCarini commented 1 week ago

Ok, I had to force-uninstall the integration and manually re-add everything ( 😢 ), but the media player is at least showing the correct current state. (Note; device is in use, so I dare not actually attempt any changes to device state, else 👶 = 😭 ...heh 😓 )

missing: Favorites showing in 'sound mode' drop down

That being said, it looks like the favorites are no longer being shown in the sound mode list; opened https://github.com/dahlb/ha_hatch/pull/131 to address (I also know this works as expected - listing the favorites in the media player 'sound mode' drop down - from the extensive testing done in https://github.com/dahlb/ha_hatch/pull/121/files )

question / feat req: selecting a favorite vs 'default' track requires different service calls

It looks like, based on how the changes between 1.17.1 to 1.19.0 were implemented (ref: https://github.com/dahlb/ha_hatch/compare/v1.17.1...v1.19.0 ), it seems as though the only way to set a 'favorite' is via the Media player: Select source service, and the only way to set a default track is via Media player: Select sound mode service. Note, I can't confirm / verify this, because as mentioned above, device currently in use - I can give it a shot in a few hours when 👶 is not 😴.

  1. Is this an intentional design decision, or just a by product of something else?
  2. Are you open to a similar implementation to https://github.com/dahlb/ha_hatch/pull/121/files where a single service can be used for either/both?

If your answer is 'yes' to 2 (which, I suspect it is since you did not raise any concerns on #121 about this), I created https://github.com/ChrisCarini/ha_hatch/pull/1 (note, this is based against the change in https://github.com/dahlb/ha_hatch/pull/131) 😄

🙏 Request for testers!! 🙏

If anyone is interested in helping me test the above 2 changes, please follow the directions in https://github.com/dahlb/ha_hatch/issues/95#issuecomment-2041051059 - I have just released v1.19.0.1 in my fork w/ the two aforementioned changes.

dahlb commented 1 week ago

@dbolton I fixed the play button to start the first available sound mode

dahlb commented 1 week ago

@ChrisCarini

  1. yes it was intentional, now that I have a gen2 rest+ I have a better understanding of how favorites work and given the first default favorite is to silently turn on the light it doesn't seem like favorites fit as a 'sound mode'
  2. I don't think a single service being used for both is a good idea as that leads to #90 where the sound mode state can not be determined because it could be either, making it only for the noise being made makes the state consistent and reliable. The current favorite is exposed as an extra entity attribute, current_favorite.
dahlb commented 1 week ago

I'm open to moving favorites to

  1. a scene entity, which might be most fitting but officially lacks state so would be hard to track as a user
  2. a switch for each one that turns on and off based on which is active, easiest to users though clutters the UI
ChrisCarini commented 1 week ago

given the first default favorite is to silently turn on the light

🤔 hmm, not sure what you mean by this - are you saying "the first default that's given when a new gen2 rest+ is added to Hatch account", or something else? Either way, these 'defaults' can be changed (specifically, I recall when onboarding my device in the app, it had me configure what I wanted for sound+colors; of course, their onboarding may have changed).

it doesn't seem like favorites fit as a 'sound mode'

tbh, 'favorites' doesn't seem to fit any of the provided methods of HA's media-player entity, but it seems trivial enough to add to the media player entity, and maintains backwards compatibility w/ the previous versions of this integration where it did successfully work.

I don't think a single service being used for both is a good idea

If you're set on a 'no' (which ofc is fine, its your code/integration to provide/document/maintain, after all 😉) for having favorites work via the media player entity (regardless of if its through select_source or select_sound_mode), it might be worth bumping major or minor version, and adding documentation (readme is prob fine) to make users more aware of this change. Had I not had the extensive experience w/ this code base + testing over the past few months, it'd be entirely non-obvious to me how to go about figuring out what to pass for the new 'set source' service call - just some 'food for thought'.

(accidentally posted before I was finished, oops! I deleted the prev one, and re-posted above)

ChrisCarini commented 1 week ago

I'm open to moving favorites to ... a scene entity, which might be most fitting

I agree, this option seems the most fitting between the two you listed, and seems to make the most sense (compared to switch), since a scene inherently is 'setting the state of several devices/entities' in HA, right?

but officially lacks state so would be hard to track as a user

I think thats ok here though, right? Why do you think state needs to be tracked? Maybe I'm missing something, but I don't think state would need to be tracked in the scene :) (it'd be tracked / updated in the entities that are modified as part of activating a scene in HA).

My thought process / rational to above is: "a favorite in Hatch is synonymous with a scene in HA - when you select a favorite it transitions multiple parts (media, brightness, etc) of the Hatch to a given state, entirely similar to how a HA scene would set multiple entities to a given state."

Anyways, that's my 3 cents given what I know about HA, and having dove fairly deep into this integration & the HA aspects that this integration has touched thus far. I'd personally love to see the setup work in a backwards compatible way (mostly so I don't have to go modify all the scripts/automations I have 😓), but in lieu of that, I'd advocate for improved documentation (to make it more clear how to set sounds & favorites via the media player entity) and possibly a major version bump to more clearly indicate to users they may need to make changes accordingly.

ChrisCarini commented 1 week ago

Oh, and also, it should go without saying, but I'll say it anyways - appreciate your work towards getting all this fixed up and working again! 👏 🎉

Also, super glad to hear you've purchased a new device to make it easier for you to test/confirm changes on! I was actually considering buying an old/used gen1 to help test my changes, but I honestly wouldn't have any immediate need for one beyond my desire to see this issue get fixed. I think I'll save the $ for more diapers. 😅

dahlb commented 1 week ago

1.20.0 moves favorites from sources to scenes, this was my first time working with scene entities but they do seem to provide a very simple user experience in the UI and are very fitting for favorites from hatch.

I updated the documentation, though documentation has never been my strong suit.

the state of the favorite is still tracked in the media_player entity because I couldn't think of a better place for it, current_step is the 0 based index of the step within the routine, given the complex time based nature of favorites I think it could be useful to control say other lights in the room when different steps activate and this attribute on the media player will allow for that.

I was just going to return the gen2 rest+ with amazon magic, but I'm liking it's charging dock so I might keep it after all.

@ChrisCarini thanks for getting the code in a good place that I was able to finish these fixes quickly with a device around :)

I tried to bump the version of 2.x but it goes against the automated release github actions I use to keep this integration managable, it likes to use minor release for breaking changes and tertiary for non breaking changes.