delfick / photons

Python3.6+ asyncio framework for interacting with LIFX devices
https://photons.delfick.com
MIT License
74 stars 6 forks source link

Home Assistant Addon Error #129

Closed Kackerlacka closed 7 months ago

Kackerlacka commented 7 months ago

In the latest version, I'm getting an error in the Home Assistant addon below. It looks like it's crashing or something, but even when it isn't in the middle of crashing it doesn't seem to be communicating to the lights. I haven't figured out if it's not working because of an error in my commands or if there's something else going on, but I figured I'd reach out here.


  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 221, in route
    route_args = self.store.determine_http_args_and_kwargs(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 562, in determine_http_args_and_kwargs
    use.extend(self._determine_keyword_args_and_kwargs(values, meta, request, kwargs))
  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 600, in _determine_keyword_args_and_kwargs
    yield self.strcs_register.create(nxt.annotation, body_raw, meta=meta)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/register.py", line 211, in create
    return CreateStructureHook.structure(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 99, in structure
    ret = hooks.convert(value, typ)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 184, in convert
    return instantiate(want, value, self.converter)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/disassemble/_creation.py", line 76, in instantiate
    return instantiator(**conv_obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: LegacyBody.__init__() missing 1 required positional argument: 'command'
2024-04-05 17:01:50,469 ERROR   photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBC8T374GY7P3EDQR3PS4E   status=500  took_seconds=0.05   uri=/v1/lifx/command
2024-04-05 17:02:02,822 INFO    photons_web_server.server Request   command=status  matcher=None    method=PUT  remote_addr=    request_identifier=01HTRBCMXZPW8X7024M25PYREN   scheme=http uri=/v1/lifx/command
2024-04-05 17:02:02,837 INFO    photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBCMXZPW8X7024M25PYREN   status=200  took_seconds=0.02   uri=/v1/lifx/command
2024-04-05 17:02:34,925 INFO    photons_web_server.server Request   command=status  matcher=None    method=PUT  remote_addr=    request_identifier=01HTRBDM96G41JQQE3QAGBFP5N   scheme=http uri=/v1/lifx/command
2024-04-05 17:02:34,940 INFO    photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBDM96G41JQQE3QAGBFP5N   status=200  took_seconds=0.02   uri=/v1/lifx/command
2024-04-05 17:02:40,945 INFO    photons_web_server.server Request   matcher=None    method=GET  remote_addr=    request_identifier=01HTRBDT5HY3DPC3J4P0037AWQ   scheme=http uri=/v1/lifx/status
2024-04-05 17:02:40,947 ERROR   photons_web_server.server Response  method=GET  remote_addr=    request_identifier=01HTRBDT5HY3DPC3J4P0037AWQ   status=404  took_seconds=0.0    uri=/v1/lifx/status
Traceback (most recent call last):
  File "handle_request", line 39, in handle_request
    Iterable,

  File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 75, in get
    return self._get(path, method, host)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 40, in _get
    raise NotFound(f"Requested URL {e.path} not found") from None
sanic.exceptions.NotFound: Requested URL /v1/lifx/status not found
2024-04-05 17:03:06,999 INFO    photons_web_server.server Request   command=status  matcher=None    method=PUT  remote_addr=    request_identifier=01HTRBEKKGR8ZQSNM03P4J901K   scheme=http uri=/v1/lifx/command
2024-04-05 17:03:07,014 INFO    photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBEKKGR8ZQSNM03P4J901K   status=200  took_seconds=0.02   uri=/v1/lifx/command
2024-04-05 17:03:39,078 INFO    photons_web_server.server Request   command=status  matcher=None    method=PUT  remote_addr=    request_identifier=01HTRBFJXZPCW7HK7XF3AZH2DX   scheme=http uri=/v1/lifx/command
2024-04-05 17:03:39,093 INFO    photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBFJXZPCW7HK7XF3AZH2DX   status=200  took_seconds=0.01   uri=/v1/lifx/command
2024-04-05 17:04:11,174 INFO    photons_web_server.server Request   command=status  matcher=None    method=PUT  remote_addr=    request_identifier=01HTRBGJ8TSKA88JX6JPJ28TW2   scheme=http uri=/v1/lifx/command
2024-04-05 17:04:11,192 INFO    photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTRBGJ8TSKA88JX6JPJ28TW2   status=200  took_seconds=0.02   uri=/v1/lifx/command
2024-04-05 17:04:40,958 INFO    photons_web_server.server Request   matcher=None    method=GET  remote_addr=    request_identifier=01HTRBHFBXKDDK9QANE59HKQ30   scheme=http uri=/v1/lifx/status
2024-04-05 17:04:40,959 ERROR   photons_web_server.server Response  method=GET  remote_addr=    request_identifier=01HTRBHFBXKDDK9QANE59HKQ30   status=404  took_seconds=0.0    uri=/v1/lifx/status
Traceback (most recent call last):
  File "handle_request", line 39, in handle_request
    Iterable,

  File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 75, in get
    return self._get(path, method, host)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 40, in _get
    raise NotFound(f"Requested URL {e.path} not found") from None
sanic.exceptions.NotFound: Requested URL /v1/lifx/status not found
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-timezone: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-timezone successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped```
delfick commented 7 months ago

What are the requests you are sending it?

On Sat, 6 Apr 2024, 11:25 Kackerlacka, @.***> wrote:

In the latest version, I'm getting an error in the Home Assistant addon below. It looks like it's crashing or something, but even when it isn't in the middle of crashing it doesn't seem to be communicating to the lights. I haven't figured out if it's not working because of an error in my commands or if there's something else going on, but I figured I'd reach out here.

File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 221, in route route_args = self.store.determine_http_args_and_kwargs( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 562, in determine_http_args_and_kwargs use.extend(self._determine_keyword_args_and_kwargs(values, meta, request, kwargs)) File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 600, in _determine_keyword_args_and_kwargs yield self.strcs_register.create(nxt.annotation, body_raw, meta=meta) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/strcs/register.py", line 211, in create return CreateStructureHook.structure( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 99, in structure ret = hooks.convert(value, typ) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 184, in convert return instantiate(want, value, self.converter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/strcs/disassemble/_creation.py", line 76, in instantiate return instantiator(**conv_obj) ^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: LegacyBody.init() missing 1 required positional argument: 'command' 2024-04-05 17:01:50,469 ERROR photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBC8T374GY7P3EDQR3PS4E status=500 took_seconds=0.05 uri=/v1/lifx/command 2024-04-05 17:02:02,822 INFO photons_web_server.server Request command=status matcher=None method=PUT remote_addr= request_identifier=01HTRBCMXZPW8X7024M25PYREN scheme=http uri=/v1/lifx/command 2024-04-05 17:02:02,837 INFO photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBCMXZPW8X7024M25PYREN status=200 took_seconds=0.02 uri=/v1/lifx/command 2024-04-05 17:02:34,925 INFO photons_web_server.server Request command=status matcher=None method=PUT remote_addr= request_identifier=01HTRBDM96G41JQQE3QAGBFP5N scheme=http uri=/v1/lifx/command 2024-04-05 17:02:34,940 INFO photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBDM96G41JQQE3QAGBFP5N status=200 took_seconds=0.02 uri=/v1/lifx/command 2024-04-05 17:02:40,945 INFO photons_web_server.server Request matcher=None method=GET remote_addr= request_identifier=01HTRBDT5HY3DPC3J4P0037AWQ scheme=http uri=/v1/lifx/status 2024-04-05 17:02:40,947 ERROR photons_web_server.server Response method=GET remote_addr= request_identifier=01HTRBDT5HY3DPC3J4P0037AWQ status=404 took_seconds=0.0 uri=/v1/lifx/status Traceback (most recent call last): File "handle_request", line 39, in handle_request Iterable,

File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 75, in get return self._get(path, method, host) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 40, in _get raise NotFound(f"Requested URL {e.path} not found") from None sanic.exceptions.NotFound: Requested URL /v1/lifx/status not found 2024-04-05 17:03:06,999 INFO photons_web_server.server Request command=status matcher=None method=PUT remote_addr= request_identifier=01HTRBEKKGR8ZQSNM03P4J901K scheme=http uri=/v1/lifx/command 2024-04-05 17:03:07,014 INFO photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBEKKGR8ZQSNM03P4J901K status=200 took_seconds=0.02 uri=/v1/lifx/command 2024-04-05 17:03:39,078 INFO photons_web_server.server Request command=status matcher=None method=PUT remote_addr= request_identifier=01HTRBFJXZPCW7HK7XF3AZH2DX scheme=http uri=/v1/lifx/command 2024-04-05 17:03:39,093 INFO photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBFJXZPCW7HK7XF3AZH2DX status=200 took_seconds=0.01 uri=/v1/lifx/command 2024-04-05 17:04:11,174 INFO photons_web_server.server Request command=status matcher=None method=PUT remote_addr= request_identifier=01HTRBGJ8TSKA88JX6JPJ28TW2 scheme=http uri=/v1/lifx/command 2024-04-05 17:04:11,192 INFO photons_web_server.server Response method=PUT remote_addr= request_identifier=01HTRBGJ8TSKA88JX6JPJ28TW2 status=200 took_seconds=0.02 uri=/v1/lifx/command 2024-04-05 17:04:40,958 INFO photons_web_server.server Request matcher=None method=GET remote_addr= request_identifier=01HTRBHFBXKDDK9QANE59HKQ30 scheme=http uri=/v1/lifx/status 2024-04-05 17:04:40,959 ERROR photons_web_server.server Response method=GET remote_addr= request_identifier=01HTRBHFBXKDDK9QANE59HKQ30 status=404 took_seconds=0.0 uri=/v1/lifx/status Traceback (most recent call last): File "handle_request", line 39, in handle_request Iterable,

File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 75, in get return self._get(path, method, host) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/sanic/router.py", line 40, in _get raise NotFound(f"Requested URL {e.path} not found") from None sanic.exceptions.NotFound: Requested URL /v1/lifx/status not found s6-rc: info: service legacy-services: stopping s6-rc: info: service legacy-services successfully stopped s6-rc: info: service legacy-cont-init: stopping s6-rc: info: service legacy-cont-init successfully stopped s6-rc: info: service fix-attrs: stopping s6-rc: info: service base-addon-timezone: stopping s6-rc: info: service base-addon-log-level: stopping s6-rc: info: service fix-attrs successfully stopped s6-rc: info: service base-addon-timezone successfully stopped s6-rc: info: service base-addon-log-level successfully stopped s6-rc: info: service base-addon-banner: stopping s6-rc: info: service base-addon-banner successfully stopped s6-rc: info: service s6rc-oneshot-runner: stopping s6-rc: info: service s6rc-oneshot-runner successfully stopped```

— Reply to this email directly, view it on GitHub https://github.com/delfick/photons/issues/129, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2V5LR7574P4CHMTVOT6DY346HLAVCNFSM6AAAAABFZ6XERWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIZDQOJXG4ZDGNY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Kackerlacka commented 7 months ago

I am trying to run a REST command:

photons_apply_theme:
  url: 'http://127.0.0.1:6100/v1/lifx/command'
  method: "put"
  payload: '{"command": "apply_theme", "args": {"theme_options": {"power_on": false, "colors": "["hex:#007780", "hex:#7d0080", "hex:#806800", "hex:#005980"]", "overrides": {"brightness": "0.8984375" } }, "matcher": {"label": "Computer Lightstrip" } }}'
delfick commented 7 months ago

@Kackerlacka well, there are two very obvious bugs I have fixed. when this is finished https://github.com/delfick/photons/actions/runs/8586988145/job/23530082106 (usually takes like 40 to 60 minutes) I'll make home assistant aware of the new version.

it doesn't seem to be communicating to the lights

If you do '{"command": "power_toggle"}' does it find and toggle the power on your lights?

delfick commented 7 months ago

I'll make home assistant aware of the new version.

that's done now

Kackerlacka commented 7 months ago

If you do '{"command": "power_toggle"}' does it find and toggle the power on your lights?

It does find all of my lights and toggles the power on them. It's just applying themes doesn't seem to work anymore (even after upgrading to 0.16.3 unfortunately).

This is what I'm getting when trying to apply a theme still (it also has the same error when trying to apply the move effect to a lightstrip):

2024-04-07 12:12:07,969 ERROR   interactor.commander.commands.legacy:LegacyCommands:legacy_put TypeError: LegacyBody.__init__() missing 1 required positional argument: 'command'   request_identifier=01HTWZK7QX00JYRAXXYHKBVQEB
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 221, in route
    route_args = self.store.determine_http_args_and_kwargs(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 562, in determine_http_args_and_kwargs
    use.extend(self._determine_keyword_args_and_kwargs(values, meta, request, kwargs))
  File "/usr/local/lib/python3.12/site-packages/photons_web_server/commander/store.py", line 600, in _determine_keyword_args_and_kwargs
    yield self.strcs_register.create(nxt.annotation, body_raw, meta=meta)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/register.py", line 211, in create
    return CreateStructureHook.structure(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 99, in structure
    ret = hooks.convert(value, typ)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/hooks.py", line 184, in convert
    return instantiate(want, value, self.converter)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/strcs/disassemble/_creation.py", line 76, in instantiate
    return instantiator(**conv_obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: LegacyBody.__init__() missing 1 required positional argument: 'command'
2024-04-07 12:12:07,980 ERROR   photons_web_server.server Response  method=PUT  remote_addr=    request_identifier=01HTWZK7QX00JYRAXXYHKBVQEB   status=500  took_seconds=0.04   uri=/v1/lifx/command
Kackerlacka commented 7 months ago

I'm also getting this when I try to send a command through the SSH & Web terminal, but I'm assuming that's an error on my part and not a bug...

image

If I change "colors" to "color" it works, but it just applies a random color:

image

For example this should've been red but it was basically every color of the rainbow

delfick commented 7 months ago

@Kackerlacka well, that "missing 1 required positional argument: 'command'" is my code failing at making a good error message (I don't think I'll have time to improve that anytime soon tbh) where it can't find the "command" option. Which means the request either doesn't have content-type application/json or the json blob doesn't have command in it.

The screenshots in your next post show what should happen with a properly formatted body.

The reason the first one fails is because "colors" needs to be a list. I imagine it used to work because before my latest rewrite, it would turn a string that's meant to be a list of strings into a list of that string, whereas it appears it no longer has that behaviour. It should work with "colors": ["blue"]

For the second screenshot, "color" is unrecognised and ignored and so it defaults the colors list to the a range of colours.

Kackerlacka commented 7 months ago

Normally I am giving it a list, like this "["hex:#007780", "hex:#7d0080", "hex:#806800", "hex:#005980"]", but the colors its applying do not match the hex colors I give it - it seems random, like you said, the default colors list. Is my hex list incorrect? It was working before.

It doesn't appear to be working in 0.14.0 after downgrading to that either.

delfick commented 7 months ago

try colors: ["hex:...", ...] instead of colors: "["...", "..."]"

On Mon, 8 Apr 2024, 09:28 Kackerlacka, @.***> wrote:

Normally I am giving it a list, like this "["hex:#007780", "hex:#7d0080", "hex:#806800", "hex:#005980"]", but the colors its applying do not match the hex colors I give it - it seems random, like you said, the default colors list. Is my hex list incorrect? It was working before.

— Reply to this email directly, view it on GitHub https://github.com/delfick/photons/issues/129#issuecomment-2041643785, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2V5JDCQSG2SCV25HMSK3Y4HJAFAVCNFSM6AAAAABFZ6XERWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBRGY2DGNZYGU . You are receiving this because you modified the open/close state.Message ID: @.***>

Kackerlacka commented 7 months ago

payload: '{"command": "apply_theme", "args": {"theme_options": {"power_on": false, "colors": ["hex:#007780", "hex:#7d0080", "hex:#806800", "hex:#005980"], "overrides": {"brightness": 0.9 } }, "matcher": {"label": "Computer Lightstrip" } }}'

This is what I am currently trying and has worked for me in the past, is this wrong?

delfick commented 7 months ago

@Kackerlacka it looks correct to me and seems to do the right thing for me. It does seem those colours you've chosen do span quite a wide range of the color spectrum, so doesn't seem to surprising to me that it'd look a little similar.

Kackerlacka commented 7 months ago

You are probably right about the colors, I will check that. I'm still struggling to get my commands working, it's probably a user error. But I input this into the terminal and it works perfectly: image But when I run this command in Home Assistant it doesn't work. To me they look the same, but maybe you can see something I don't. Can you see any reason why the second photo wouldn't work? image

delfick commented 7 months ago

I spent like an hour trying to get my hassio to work, but it hates me and refuses to start hassio supervisor (and honestly I'm not a fan of hassio in the first place) and I give up. Maybe try "http://homeassistant.local:6100" instead of "http://localhost:6100" and see if that works.

delfick commented 7 months ago

also try adding

content_type: 'application/json'
Kackerlacka commented 7 months ago

Wow that worked... I can't believe I forgot to include that. Looks like I'm all good now, thank you so much for your help!

delfick commented 7 months ago

nice. tbf I believe the content_type was assumed as json before, but it's no longer assumed anymore. Out of interest does it work still with "localhost:6100" when you have the content type set?

Kackerlacka commented 7 months ago

It does indeed work with "localhost:6100" when I have the content type set!

delfick commented 7 months ago

awesome :)

On Mon, 29 Apr 2024, 05:09 Kackerlacka, @.***> wrote:

It does indeed work with "localhost:6100" when I have the content type set!

— Reply to this email directly, view it on GitHub https://github.com/delfick/photons/issues/129#issuecomment-2081605832, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2V5IURQAJ75OWY34FEUDY7VCNLAVCNFSM6AAAAABFZ6XERWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRGYYDKOBTGI . You are receiving this because you modified the open/close state.Message ID: @.***>