PiotrMachowski / Home-Assistant-test-components-SmartThings

Apache License 2.0
3 stars 1 forks source link

409 Conflict #1

Open CarsonF opened 3 years ago

CarsonF commented 3 years ago

Hey I've been using this for my two TVs and it's working great! Thanks for maintaining it.

I do have a small problem with my older one (maybe 2016). Sometimes the state on/off state is incorrect. I'm not sure how this happens, perhaps turning it off with the physical remote or on via CEC.

With this TV, SmartThings is unable to turn the TV on when it is off. I use an IR command with Universal Media Player to work around this.

So when the TV is off, SmartThings says the TV is Unavailable instead of Off.

The second symptom is whenever you try to take a action on the TV while HA thinks it's on but it's actually off SmartThings sends back a 409 Conflict.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 760, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/universal/media_player.py", line 531, in async_turn_off
    await self._async_call_service(SERVICE_TURN_OFF, allow_override=True)
  File "/usr/src/homeassistant/homeassistant/components/universal/media_player.py", line 249, in _async_call_service
    await async_call_from_config(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 165, in async_call_from_config
    await hass.services.async_call(**params, blocking=blocking, context=context)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 760, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call
    await result
  File "/config/custom_components/smartthings/media_player.py", line 100, in async_turn_off
    await self._device.switch_off(set_status=True)
  File "/usr/local/lib/python3.8/site-packages/pysmartthings/device.py", line 1013, in switch_off
    result = await self.command(component_id, Capability.switch, Command.off)
  File "/usr/local/lib/python3.8/site-packages/pysmartthings/device.py", line 825, in command
    response = await self._api.post_device_command(
  File "/usr/local/lib/python3.8/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.8/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.8/site-packages/pysmartthings/api.py", line 376, in request
    resp.raise_for_status()
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 1000, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 409, message='Conflict', url=URL('https://api.smartthings.com/v1/devices/my-tv-uuid/commands')

I think catching this error and setting the TV state to off would be a good fix.

I'm not sure why SmartThings doesn't communicate to this code that the TV is off. Maybe this code checks explicitly for Off and ST sends Unavailable instead?

PiotrMachowski commented 3 years ago

Woah, I haven't expected that anybody used this version 😄 I will try to check it out