Devices

Normally you will never create any instances of a Device class, they are created automatically as the server informs the client of their existence via the INDI protocol.

So for example, you will have your IPyClient object, and as it is a mapping of device name to devices, you have:

device = ipyclient[devicename]

Devices are mappings of vectors:

vector = ipyclient[devicename][vectorname]

Vectors are mappings of member values:

value = ipyclient[devicename][vectorname][membername]

These mappings obey dictionary methods allowing you to iterate over items, keys and values.

class Device(devicename, client)

An instance of this is created for each device as data is received.

snapshot()

Take a snapshot of the device and returns an object which is a restricted copy of the current state of the device and its vectors. Vector methods for sending data will not be available. This copy will not be updated by events. This is provided so that you can handle the device data, without fear of the value changing.

Attributes

The attributes of the device object are:

self.devicename

self.user_string

This is initially an empty string, but can be set by your code to any string you like.

self.itemid

An integer associated with this device when the client first learns of the device. Created by calling the client.create_itemid() method.

self.messages

This is a collections.deque of item tuples (Timestamp, message).

Where the messages are received from the INDI server and are associated with the device. The deque has a maxlen=8 value set, and so only the last eight messages will be available.

Note, messages are added with ‘appendleft’ so the newest message is messages[0] and the oldest message is messages[-1] or can be obtained with .pop()

self.enable

This will normally be True, but will become False if the INDI server sends a request to delete the device.

Device Snapshot

The snapshot() method of the device returns a SnapDevice object which is a copy of the state of the device and vectors. This could be used if you wish to pass this state to your own routines, perhaps to record values in another thread without danger of them being updated.

The snapshot is a mapping of vector name to snapshot copies of vectors, but without the methods to send vector updates.

class SnapDevice(devicename, messages, user_string, itemid)

This object is used as a snapshot of this device It is a mapping of vector name to vector snapshots

dictdump(inc_blob=False, inc_user_string=False, inc_itemid=False)

Returns a dictionary of this device information and is used to generate the JSON output. If any BLOB vectors are included and inc_blob is False, the BLOB values will be given as None in the dictionary, set inc_blob to True to also include the BLOB in the dictionary.

dump(fp, indent=None, separators=None, inc_blob=False, inc_user_string=False, inc_itemid=False)

Serialize the snapshot as a JSON formatted stream to fp, a file-like object. This uses the Python json module which always produces str objects, not bytes objects. Therefore, fp.write() must support str input. If any BLOB vectors are included and inc_blob is False, the BLOB values will be given as Null in the file, set inc_blob to True to also include the BLOB.

dumps(indent=None, separators=None, inc_blob=False, inc_user_string=False, inc_itemid=False)

Returns a JSON string of the snapshot. If any BLOB vectors are included and inc_blob is False, the BLOB values will be given as Null in the string, set inc_blob to True to also include the BLOB.

The dumps and dump methods can be used to create JSON records of the device state.

The SnapDevice object has attributes, which are copies of the Device attributes.

self.devicename

self.user_string

self.itemid

self.messages

The messages attribute is cast as a list rather than a collections.deque. It is the messages at the point the snapshot is taken, it does not update.

self.enable

True if any vector of this device has enable True, otherwise False if the device has been deleted. This does not update.