automicus / PyISY

Python module for interactive with the ISY-994 Insteon controller.
Other
16 stars 22 forks source link

2.x setting auto_update= True results in KeyError: 'sid' #384

Closed jimboca closed 1 year ago

jimboca commented 1 year ago

Polyglot 3 uses pyisy (yes still using 2.x) and when setting auto_update=True I get this error.

2023-03-19 19:58:42,087 ELK-16986  elkm1_lib.notify   ERROR    notify:notify: 'sid'
Traceback (most recent call last):
  File "/var/polyglot/.local/lib/python3.9/site-packages/elkm1_lib/notify.py", line 39, in notify
    observer(**notify_parameters)
  File "/usr/home/admin/dev/pg3/udi-poly-ELK/nodes/Controller.py", line 534, in sync_complete
    self.pyisy.auto_update = True
  File "/var/polyglot/.local/lib/python3.9/site-packages/pyisy/isy.py", line 138, in auto_update
    self._events.running = val
  File "/var/polyglot/.local/lib/python3.9/site-packages/pyisy/events.py", line 146, in running
    self.unsubscribe()
  File "/var/polyglot/.local/lib/python3.9/site-packages/pyisy/events.py", line 198, in unsubscribe
    msg = self._create_message(strings.UNSUB_MSG)
  File "/var/polyglot/.local/lib/python3.9/site-packages/pyisy/events.py", line 70, in _create_message
    body = body.format(**self.data)
KeyError: 'sid'
jimboca commented 1 year ago

It looks like this is happening because it's trying to send UNSUB_MSG but there is no sid since a subscription hasn't been started previously?

shbatm commented 1 year ago

Have you had it working any time recently? Could be related to the last change here: https://github.com/automicus/PyISY/commit/da839933585274ea866c205e6842263114c01e85 if you haven't used it since Jan-2022

shbatm commented 1 year ago

Also, is this your nodeserver on PG3 or PG3 itself that's still running V2? I'd like to take a look at what it would take to move it to V4 (https://github.com/shbatm/pyisyox V1). Once I get this next version finished, I'm not intending to keep maintaining this repo since V4 has an entirely new structure.

jimboca commented 1 year ago

I still have my node server which sets auto update: https://github.com/UniversalDevicesInc-PG3/udi-poly-hue-emu/blob/master/ISYHueEmu.py#L75 Which still works.

Now another nodeserver needs to use pyisy so I wanted to use the PG3 builtin method so users don't need to enter the ISY host/port/user/password: https://github.com/UniversalDevicesInc/udi_python_interface/blob/master/udi_interface/isy.py

My code calls init_isy to setup the isy/pyisy connection: https://github.com/UniversalDevicesInc-PG3/udi-poly-ELK/blob/master/nodes/Controller.py#L261 https://github.com/UniversalDevicesInc-PG3/udi-poly-ELK/blob/master/nodes/Controller.py#L508 and sets auto update which fails: https://github.com/UniversalDevicesInc-PG3/udi-poly-ELK/blob/master/nodes/Controller.py#L534

I'm sure Bob would appreciate you helping convert PG3 pyisy to your new pyisyox in the udi_interface.

jimboca commented 1 year ago

I added this to both nodeservers: pyisy_version = pkg_resources.get_distribution("pyisy").version and confirmed they both user 2.1.6

jimboca commented 1 year ago

BTW, my intention is to use pyisy contained in PG3, then I'd move my other nodeserver to use the same. Then we could look at converting both to use pyisy 3, now 4. I'd like to get on a supported version as well and understand you don't want to support 2.x, it's just painful to use an async library in a non-async program, but I've done it with a couple others so this was next...

shbatm commented 1 year ago

I pushed a minor change to the V2 branch -- it looks like there's a larger issue buried in there: it looks like the stream is either not connecting on your ELF NS, or it's immediately disconnecting after sending the subscribe message (which is why there's no stream id)--which is why one NS is working and one is not throwing the same errors.

I'll take a closer look when I get a chance and see if there's an issue with how the PG3 library is connecting, if that's the main difference.

As for the async in a non-async module--one of my goals for pyisyox is to allow that asyncio loop to be self contained if necessary (similar to paho-mqtt). The biggest issue will be getting feedback for service calls to the ISY; it'll need a synchronizing function that blocks waiting for a response.

jimboca commented 1 year ago

Thanks! I'll pull that version and test.

The only difference I can see is that PG3 uses https and my other nodeserver doesn't.

That would be great to have a self contained asyncio loop!

jimboca commented 1 year ago

Sorry, think I found it... Indentation error, auto_update=True was inside a loop. So it is could still be a "bug", but hopefully I don't care. again sorry for wasting your time.