hyperb1iss / signalrgb-homeassistant

Transform your smart home lighting with the power of SignalRGB, now integrated directly into Home Assistant!
Apache License 2.0
7 stars 1 forks source link

v0.5.0 and v0.6.0 cannot connect to SignalRGB API #4

Open WhimsySpoon opened 4 weeks ago

WhimsySpoon commented 4 weeks ago

Any commands from Home Assistant Core throw the exception below.

{
"api_version": "1.0",
"data": {
"attributes": {
"name": "Gradient Wave"
},
"id": "-Me3BsMN_hIlzeJwFbMs",
"links": {
"self": "[/api/v1/lighting/effects/-Me3BsMN_hIlzeJwFbMs](http://[hostname]:16038/api/v1/lighting/effects/-Me3BsMN_hIlzeJwFbMs)"
},
"type": "effect"
},
"id": 36,
"method": "[/api/v1/lighting](http://[hostname]:16038/api/v1/lighting)",
"params": {},
"status": "ok"
}

The exception:

2024-08-14 09:55:39.995 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140310035532384] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 130, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://[hostname]:16038/api/v1/lighting/enabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 373, in enabled
    response_data = self._request(
                    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 146, in _request
    error_data = e.response.json().get("errors", [{}])[0]
                 ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 626, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/signalrgb/light.py", line 156, in async_turn_on
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 379, in enabled
    raise SignalRGBException(
signalrgb.client.SignalRGBException: Failed to set enabled state: Expecting value: line 1 column 1 (char 0)
2024-08-14 09:55:44.357 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140310035532384] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 130, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://[hostname]:16038/api/v1/lighting/enabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 373, in enabled
    response_data = self._request(
                    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 146, in _request
    error_data = e.response.json().get("errors", [{}])[0]
                 ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 637, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/config/custom_components/signalrgb/light.py", line 178, in async_turn_off
    await self.hass.async_add_executor_job(setattr, self._client, "enabled", False)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 379, in enabled
    raise SignalRGBException(
signalrgb.client.SignalRGBException: Failed to set enabled state: Expecting value: line 1 column 1 (char 0)
WhimsySpoon commented 4 weeks ago

Exception appears slightly different in 0.6.0:

[139853489545296] Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 130, in _request
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://[hostname]:16038/api/v1/lighting/enabled

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 373, in enabled
    response_data = self._request(
                    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 146, in _request
    error_data = e.response.json().get("errors", [{}])[0]
                 ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 626, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/signalrgb/light.py", line 184, in async_turn_on
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/signalrgb/client.py", line 379, in enabled
    raise SignalRGBException(
signalrgb.client.SignalRGBException: Failed to set enabled state: Expecting value: line 1 column 1 (char 0)
hyperb1iss commented 4 weeks ago

Do you have the latest SignalRGB? The enabled and brightness states were just added a week ago, and they don't give us a way to determine the version easily from the API.

WhimsySpoon commented 4 weeks ago

Looks like it was added in the beta. I'm running the latest stable, so might explain this.

Control Global brightness with Macros and the local API.

Will update to the beta and report back...

hyperb1iss commented 4 weeks ago

Oh geez yeah it's the beta. Sorry about that, I've just got automatic updates on!

I might be able to figure out the right behavior based on whether these properties even exist in the json responses, I'll have a peek after work today. Also grab 0.6.1, it fixes a nasty state tracking issue

WhimsySpoon commented 4 weeks ago

Please don't apologise! This integration is amazing!!

I gave just installed the beta and 0.6.0 and 0.6.1 is now working perfectly - thank you!

Additionally, Brightness and on/off work without the need for the Good Night! effect.

I don't know how frequently SignalRGB promotes beta releases, but if it's likely to take a while, I'd be happy to submit a PR for the readme.md confirming that the beta is required to save the need for potential spaghetti code to handle the API version differences.

hyperb1iss commented 4 weeks ago

Yeah that would be great, but it probably needs to adapt to different SignalRGB versions anyway so I'll still dig into it.

Have you tried hyper-light-card yet? I just made the first release!

WhimsySpoon commented 4 weeks ago

PR for an updated readme is with you.

I have tried the new card and it's amazing!