indilib / pyindi-client

GNU General Public License v3.0
21 stars 8 forks source link

getDevices() returns incorrect devices #42

Open rkaczorek opened 1 year ago

rkaczorek commented 1 year ago

I'm not sure if that's INDI backend issue (INDI Library: 2.0.3) or pyindi-client issue (1.9.1) or I'm missing something. Looks like getDevices() client function always returns devices set at the first time client connected to INDI server. The value is not updated between reconnects.

How to reproduce:

  1. Simple INDI client working in infinite loop and printing names of active devices (see below)
  2. While script running start indiserver with 3 drivers of your choice. Observe list of connected devices printed by the script.
  3. Stop indiserver (DO NOT restart python script) and rerun indiserver with 5 drivers of your choice. Observe list of connected devices printed by the script. You will notice that not all devices are printed out by the script.
#!/usr/bin/env python3
# coding=utf-8

import PyIndi, time

class IndiClient(PyIndi.BaseClient):
    def __init__(self):
        super(IndiClient, self).__init__()

    def serverConnected(self):
        '''Emmited when the server is connected.'''
        print(f"Server connected ({self.getHost()}:{self.getPort()})")

    def serverDisconnected(self, code):
        '''Emmited when the server gets disconnected.'''
        print(f"Server disconnected (exit code = {code},{self.getHost()}:{self.getPort()})")
        self.disconnectServer() # double shot to disconnect

indiclient = IndiClient()
indiclient.setServer("localhost", 7624)

while True:
    while not indiclient.isServerConnected():
        indiclient.connectServer()

        if indiclient.isServerConnected():
            time.sleep(1)
        else:
            print(f"Cannot connect to INDI server on {indiclient.getHost()}:{str(indiclient.getPort())}. Retrying in 5 seconds.")
            time.sleep(5)

    devices = indiclient.getDevices() # Get all devices from INDI server
    for device in devices:
        device_name = device.getDeviceName()
        print(device_name)

    time.sleep(1)