samuelspagl / ha_samsung_soundbar

YASSI (Yet another Samsung Soundbar integration) is a HomeAssistant integration for Samsung Soundbars.
https://ha-samsung-soundbar.vercel.app
MIT License
44 stars 2 forks source link

[BUG] Getting a 409 error when trying to set up HW-Q950T #13

Open PrMinisterGR opened 9 months ago

PrMinisterGR commented 9 months ago

Logger: homeassistant.config_entries Source: config_entries.py:406 First occurred: 10:49:04 (7 occurrences) Last logged: 11:10:00

Error setting up entry samsung_soundbar for samsung_soundbar
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/samsung_soundbar/__init__.py", line 50, in async_setup_entry
    await soundbar_device.update()
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 49, in update
    await self._update_soundmode()
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 69, in _update_soundmode
    await self.update_execution_data(["/sec/networkaudio/soundmode"])
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 363, in update_execution_data
    return await self.device.command("main", "execute", "execute", argument)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysmartthings/device.py", line 842, in command
    response = await self._api.post_device_command(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysmartthings/api.py", line 147, in post_device_command
    return await self.post(API_DEVICE_COMMAND.format(device_id=device_id), data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysmartthings/api.py", line 395, in post
    return await self.request("post", self._api_base + resource, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysmartthings/api.py", line 376, in request
    resp.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1060, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 409, message='Conflict', url=URL('https://api.smartthings.com/v1/devices/{SOUNDBAR_DEVICE_ID}/commands')

I get the above when add the integration, the integrated Home Assistant Smart Things integration works, but I have no controls except power for my HW-Q950T Samsung soundbar.

samuelspagl commented 9 months ago

Hi @PrMinisterGR

You probably tried it out multiple times right? 😅 I know dumb question but still.

409 generally stands for a conflict or also for example if somebody is trying to create a resource thats already existing.

Do you think it would be possible for you to change something in the code, to see if that helps you?

You can get access to the config directory by using the "Visual Studio Code" Addon. You need to edit the SoundbarDevice.py file. The following is a short sketch of where to find it.

config
|- custom_components
  |- samsung_soundbar
    |- api_extension
      |- SoundbarDevice.py # This is the file you need to edit

In the update function could you please try to comment out (#) the following line

await self._update_soundmode()

and then try again?

tjorim commented 9 months ago

I'm getting the same issue on a Q700C. Already tried commenting out the line as suggested. Modified from b2.

Logger: homeassistant.config_entries
Source: config_entries.py:442
First occurred: 00:46:04 (1 occurrences)
Last logged: 00:46:04

Error setting up entry samsung_soundbar for samsung_soundbar
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 442, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/samsung_soundbar/__init__.py", line 50, in async_setup_entry
    await soundbar_device.update()
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 53, in update
    await self._update_advanced_audio()
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 133, in _update_advanced_audio
    await self.update_execution_data(["/sec/networkaudio/advancedaudio"])
  File "/config/custom_components/samsung_soundbar/api_extension/SoundbarDevice.py", line 379, in update_execution_data
    return await self.device.command("main", "execute", "execute", argument)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pysmartthings/device.py", line 842, in command
    response = await self._api.post_device_command(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pysmartthings/api.py", line 147, in post_device_command
    return await self.post(API_DEVICE_COMMAND.format(device_id=device_id), data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pysmartthings/api.py", line 395, in post
    return await self.request("post", self._api_base + resource, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pysmartthings/api.py", line 376, in request
    resp.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1060, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 409, message='Conflict', url=URL('https://api.smartthings.com/v1/devices/my-own-random-code/commands')
samuelspagl commented 9 months ago

Okay, this really bugs me, because I'm not quite understanding why it's working for others but not for you guys. Let's start from the beginning: When you open the SmartThings App and tap on your Soundbar, what kind of settings can you set?

tjorim commented 9 months ago

I noticed my soundbar was not connected to Wi-Fi anymore (also showed as offline in the app). I reset the soundbar and configured it again. I returned the source code to original (b3) and set it up. All working well for me! 👍

samuelspagl commented 9 months ago

Ah interesting good to know. Could @PrMinisterGR face the same issue of his soundbar not being connected with the wifi?