vinenoobjelly / jellyfishlights-py

12 stars 5 forks source link

getRunPattern issues (and publication to PyPI) #1

Closed bdunn44 closed 1 year ago

bdunn44 commented 1 year ago

Hi there - I see that you've recently added support for the get runPattern method. Thanks for that! I tested it out this evening and ran into a couple of issues.

First, when running getRunPattern(zones=None) it picks one of my zones to send the request for (instead of defaulting to all zones as is the behavior for other functions).

Also, I got this error:

Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/python/lib/python3.10/site-packages/jellyfishlightspy/jellyfishmain.py", line 85, in getRunPattern
    runPatternsClass = RunPatternClassFromDict(runPatterns)
  File "/usr/local/python/lib/python3.10/site-packages/jellyfishlightspy/runPattern.py", line 95, in RunPatternClassFromDict
    return RunPatternClass.from_dict(s)
  File "/usr/local/python/lib/python3.10/site-packages/jellyfishlightspy/runPattern.py", line 57, in from_dict
    data = RunPatternDatafromdict(json.loads(obj.get("data")))
  File "/usr/local/python/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/python/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/python/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here is the JSON sent and received:

Sending: {"cmd": "toCtlrGet", "get": [["runPattern", "Back lower"]]}
Recieved: {"cmd":"fromCtlr","runPattern":{"data":"","file":"Special Effects/Pink Waves","id":"Back lower","state":1,"zoneName":["Back lower"]}}

Hope you are already aware of this and working on a fix. I may work on a fix myself when I have time and will submit a PR if I do.

Last, are you planning to publish these changes to PyPI? I'm working on a third party integration and will need these changes published to take advantage of them.

vinenoob commented 1 year ago

The selection is on purpose at the moments, as I intend the function to just get one run runPattern (I could be convinced to change it). As for the error, I think I forgot to account for the case where we have no data because we have a defined pattern. I'm away so it's hard for me to know for sure

bdunn44 commented 1 year ago

Makes sense. For my use case I'll need to get the state of all zones at once every time so I'd personally prefer to have this match the pattern of getting zones and the run pattern list (where it's added to connectAndGetData with results stored), but it's no big deal to loop through the zones either.

You plan to release a new version to PyPI once this is ready for prime time, right?

vinenoob commented 1 year ago

Yeah it should probably follow other things where it returned using a container (I think I've been using dicts?). I plan on releasing when it is ready but I'm having to remind myself how to do it as I have forgotten and I lost my previous hard drive I did it on

bdunn44 commented 1 year ago

@vinenoob tested out you latest commit and everything's working well. Hope to get a PyPI update soon - will keep this open to track that. Please let me know if/when it's available

vinenoob commented 1 year ago

@bdunn44 I have released it. I also wanted to give the explanation as to why I have the getRunPattern the way it is. The other API commands to get Zones and Patterns can be done in one "ask and receive" cycle. However, for runPatterns, you can ask for many runPatterns at once but for each runPattern you ask for you get a separate response. So it was simpler at the moment to just retrieve one runPattern at a time. I am contemplating creating a getRunPatterns function that does get them all (or whatever you wanted) in one function call

vinenoob commented 1 year ago

Just added getRunPatterns, the multiple fetch version of getRunPattern

bdunn44 commented 1 year ago

Fantastic! Thanks @vinenoob. I've got my code (https://github.com/bdunn44/hass-jellyfish-lighting) working well with the single getRunPattern function. I'll test out getRunPatterns as well and let you know if I run into any trouble

bdunn44 commented 1 year ago

@vinenoob I'm running into an issue that I'm hoping you can help me out with.... I am now getting a connection error (see below) while testing this library. I'm getting the same error with 0.2.0 as well as 0.3.0, so it's not being caused by the code you pushed. I strongly suspect it's being caused by a firmware upgrade I applied today. I don't see anywhere in the app that I can check the firmware version, but it should be the latest. Can you help look into this? I can call tech support if that's the best place to start, just let me know.

PS C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test> python .\test.py
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 108, in recv
    bytes_ = _recv()
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 87, in _recv
    return sock.recv(bufsize)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 87, in connectAndGetData
    self.__ws.connect(f"ws://{self.__address}:9000")
  File "C:\Python39\lib\site-packages\websocket\_core.py", line 253, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 145, in _get_resp_headers
    status, resp_headers, status_message = read_headers(sock)
  File "C:\Python39\lib\site-packages\websocket\_http.py", line 312, in read_headers
    line = recv_line(sock)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 131, in recv_line
    c = recv(sock, 1)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 110, in recv
    raise WebSocketTimeoutException("Connection timed out")
websocket._exceptions.WebSocketTimeoutException: Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test\test.py", line 4, in <module>
    controller.connectAndGetData()
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 91, in connectAndGetData
    raise BaseException("Could not connect to controller at " + self.__address)
BaseException: Could not connect to controller at jellyfish-controller.my-domain.my-tld
vinenoob commented 1 year ago

@bdunn44 It seems like you are trying to connect with hostname as opposed to ip address

vinenoob commented 1 year ago

I would see if you can controller your lights with either the cloud or designer app

bdunn44 commented 1 year ago

@vinenoob I've used hostname this whole time and it has worked. But using the IP address has the same timeout issue regardless (see below). The cloud app still works... and so does the home assistant integration when I run it from another computer (!!) Looks like an issue specific to this machine... will need to look into it. Disregard for now

PS C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test> python .\test.py
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 108, in recv
    bytes_ = _recv()
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 87, in _recv
    return sock.recv(bufsize)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 87, in connectAndGetData
    self.__ws.connect(f"ws://{self.__address}:9000")
  File "C:\Python39\lib\site-packages\websocket\_core.py", line 253, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 145, in _get_resp_headers
  File "C:\Python39\lib\site-packages\websocket\_http.py", line 312, in read_headers
    line = recv_line(sock)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 131, in recv_line
    c = recv(sock, 1)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 110, in recv
    raise WebSocketTimeoutException("Connection timed out")
websocket._exceptions.WebSocketTimeoutException: Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test\test.py", line 4, in <module>
    controller.connectAndGetData()
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 91, in connectAndGetData
    raise BaseException("Could not connect to controller at " + self.__address)
BaseException: Could not connect to controller at jellyfish-controller.lovejoy.dunnfam.ly
PS C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test> python .\test.py
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 108, in recv
    bytes_ = _recv()
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 87, in _recv
    return sock.recv(bufsize)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 87, in connectAndGetData
    self.__ws.connect(f"ws://{self.__address}:9000")
  File "C:\Python39\lib\site-packages\websocket\_core.py", line 253, in connect
    self.handshake_response = handshake(self.sock, url, *addrs, **options)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 57, in handshake
    status, resp = _get_resp_headers(sock)
  File "C:\Python39\lib\site-packages\websocket\_handshake.py", line 145, in _get_resp_headers
    status, resp_headers, status_message = read_headers(sock)
  File "C:\Python39\lib\site-packages\websocket\_http.py", line 312, in read_headers
    line = recv_line(sock)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 131, in recv_line
    c = recv(sock, 1)
  File "C:\Python39\lib\site-packages\websocket\_socket.py", line 110, in recv
    raise WebSocketTimeoutException("Connection timed out")
websocket._exceptions.WebSocketTimeoutException: Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\kbrys\Documents\Tech\Home Assistant Projects\Jellyfish Lighting\jellfishlights-py-test\test.py", line 5, in <module>
    controller.connectAndGetData()
  File "C:\Python39\lib\site-packages\jellyfishlightspy\jellyfishmain.py", line 91, in connectAndGetData
    raise BaseException("Could not connect to controller at " + self.__address)
BaseException: Could not connect to controller at 1.1.1.1
bdunn44 commented 1 year ago

@vinenoob do you know if any network configuration/security changes were introduced with the latest firmware update? I discovered that I'm able to connect to the controller if I'm on the same subnet but the connection is now being blocked otherwise. I have a separate subnet for my IoT devices and haven't made any changes to my network configuration. I was able to connect across subnets before the firmware upgrade and it now fails. Have layer 3 connections been disabled?

Synse commented 1 year ago

I don't see anywhere in the app that I can check the firmware version

You can see the current firmware version at http://[controller_ip]:8080/ (html page) or http://[controller_ip]:8080/api/v2/version (plain text). The latest version is visible at http://[controller_ip]:8080/api/v2/latest as json.

bdunn44 commented 1 year ago

Thanks @Synse! My current firmware version is 3.0.22. I don't know which version I upgraded from, so tough to know in which version this change could have been introduced. I had my system installed in early December if that's any help

Synse commented 1 year ago

You were probably on 3.0.15 but I don't know of a way to see the previously installed version.

https://jellyfishlighting.com/app-updates/

I've been on 3.0.15 for a few months and noticed the .22 update the other day but I think I'll hold off on updating for a bit longer.

bdunn44 commented 1 year ago

Going to close this issue as all the getRunPattern functionality is working as expected in the version published to PyPI. I can work around the new network restrictions, so no worries. Thanks for the support @vinenoob!