sbidy / pywizlight

A python connector for WiZ devices
MIT License
463 stars 79 forks source link

Unable to change bulb state #154

Open janek515 opened 2 years ago

janek515 commented 2 years ago

OS: Windows 11 22623.875 Python: 3.11

Hi, I am able to connect to the bulb and to get its state info back, but when i try altering its state in any way using bulb.turn_off() or bulb.set_state(PilotBuilder(colortemp=color_temp)) the following error message is printed:

Fatal write error on datagram transport
protocol: <pywizlight.protocol.WizProtocol object at 0x00000236AA61F650>
transport: <_ProactorDatagramTransport fd=760 read=<_OverlappedFuture cancelled>>
Traceback (most recent call last):
  File "C:\...\Python311\Lib\asyncio\proactor_events.py", line 529, in _loop_writing
    self._write_fut = self._loop._proactor.send(self._sock,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'send'
127.0.0.1 - - [06/Nov/2022 14:08:55] "POST /v1/set?ct=5050&bri=1.000000 HTTP/1.1" 500 -
Traceback (most recent call last):
  File "C:\...\Python311\Lib\asyncio\tasks.py", line 490, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\pywizlight\bulb.py", line 758, in send
    resp = await asyncio.wait_for(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\Python311\Lib\asyncio\tasks.py", line 492, in wait_for
    raise exceptions.TimeoutError() from exc
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 2548, in __call__
    return self.wsgi_app(environ, start_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 2528, in wsgi_app
    response = self.handle_exception(e)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\flask\app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\asgiref\sync.py", line 218, in __call__
    return call_result.result()
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\...\Python311\Lib\concurrent\futures\_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\...\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\asgiref\sync.py", line 284, in main_wrap
    result = await self.awaitable(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\code\flux\app.py", line 46, in v1set
    await set_color_temp()
  File "D:\code\flux\app.py", line 34, in set_color_temp
    await bulb.turn_off()
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\pywizlight\bulb.py", line 630, in turn_off
    await self.send({"method": "setPilot", "params": {"state": False}})
  File "C:\...\pypoetry\Cache\virtualenvs\flux-2fB9oRMh-py3.11\Lib\site-packages\pywizlight\bulb.py", line 762, in send
    raise WizLightConnectionError(str(ex)) from ex
pywizlight.exceptions.WizLightConnectionError
sbidy commented 2 years ago

It seems to me that you can't connect successfully to the bulb. Please try to send a nc to the bulb to test the basic connectivity. See here: https://github.com/sbidy/pywizlight/issues/89#issuecomment-947428357

janek515 commented 2 years ago

It appears to be something else as the response seems fine.

{"method":"getSystemConfig","env":"pro","result":{"mac":"6c29901***","homeId":763***,"roomId":11***,"rgn":"eu","moduleName":"ESP03_SHTW1W_01","fwVersion":"1.28.0","groupId":0,"ping":0}}
sbidy commented 2 years ago

Can you please try to send the same command (turn off) via nc: {"method": "setPilot", "params": {"state": False}} (replace the part after echo)

janek515 commented 2 years ago

It works as expected and returns {"method":"setPilot","env":"pro","result":{"success":true}}