Events¶
As received data arrives from the server, events are raised. These events are automatically used to create the Devices, Vectors and Members that describe the device properties.
After setting any new values into the Vectors and members, the IPyClient rxevent(event) coroutine method is called. As default this does nothing, consisting merely of the pass command. If you wish to act on the event received you could create your own class, inheriting from IPyClient and override this method,
Events are of different types, which initially define a vector, and then set existing vector values. These event objects are described here.
You should never need to instantiate these classes yourself.
The classes can be imported directly from the indipyclient module, which may be needed if you are checking the event class using isinstance, or pattern matching.
- class Message(root, device, client)¶
This contains attribute ‘message’ with the message string sent by the remote driver. Attribute devicename could be None if the driver is sending a system wide message.
Attributes
self.device
Could be None if this is a global message from the server not assigned to a device
self.devicename
Could be None
self.vectorname
Always None, as this message is either a global message or only associated with a device
self.vector
None
self.root
An xml.etree.ElementTree object of the received xml data.
self.timestamp
A datetime.datetime object.
self.message
If self.device is None, the tuple (self.timestamp, self.message) is appended to the IPyClient messages deque.
If self.device is given, the tuple is appended to the device messages deque.
self.eventtype
Set to the string “Message”.
- class getProperties(root, device, client)¶
This may have a device and name, both may be None But there may still be a devicename and vectorname for an unknown device
The getProperties request is normally sent from the client to Drivers, and so is not normally received by a client. However one driver can snoop on another by transmitting a getProperties, which may therefore be received here. Usually it should be ignored by a client.
Attributes
self.device
Could be None
self.devicename
Could be None
self.vectorname
Could be None
self.vector
None
self.root
An xml.etree.ElementTree object of the received xml data.
self.timestamp
A datetime.datetime object.
self.eventtype
Set to the string “getProperties”.
- class delProperty(root, device, client)¶
The remote driver is instructing the client to delete either a device or a vector property. This contains attribute vectorname, if it is None, then the whole device is to be deleted. A ‘message’ attribute contains any message sent by the client with this instruction. This event will automatically set the appropriate enable flag to False in the effected device and vectors.
Attributes
self.device
self.devicename
self.vectorname
Could be None, to indicate the whole device is deleted.
self.vector
None
self.root
An xml.etree.ElementTree object of the received xml data.
self.timestamp
A datetime.datetime object.
self.message
self.eventtype
Set to the string “Delete”.
- class defSwitchVector(root, device, client)¶
The remote driver has sent this to define a switch vector property, this is a mapping of membername:value
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.label
self.group
self.state
self.perm
self.rule
One of ‘OneOfMany’, ‘AtMostOne’, ‘AnyOfMany’
self.timeout
self.memberlabels
Dictionary with key member name and value being label
self.eventtype
Set to the string “Define”.
- class defTextVector(root, device, client)¶
The remote driver has sent this to define a text vector property, this is a mapping of membername:value.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.label
self.group
self.state
self.perm
self.timeout
self.memberlabels
Dictionary with key member name and value being label
self.eventtype
Set to the string “Define”.
- class defNumberVector(root, device, client)¶
The remote driver has sent this to define a number vector property, this is a mapping of membername:value. Its attributes memberlabels gives further description of members, being a dictionary of membername:(label, format, min, max, step).
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.label
self.group
self.state
self.perm
self.timeout
self.memberlabels
Dictionary with key member name and value being a tuple of (label, format, min, max, step).
self.eventtype
Set to the string “Define”.
- class defLightVector(root, device, client)¶
The remote driver has sent this to define a light vector property. This is a mapping of membername:value.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.label
self.group
self.state
self.memberlabels
Dictionary with key member name and value being label
self.eventtype
Set to the string “Define”.
- class defBLOBVector(root, device, client)¶
The remote driver has sent this to define a BLOB vector property.
However this class does not have an object mapping of member name to value, since values are not given in defBLOBVectors
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.label
self.group
self.state
self.perm
self.timeout
self.memberlabels
Dictionary with key member name and value being label
self.eventtype
Set to the string “DefineBLOB”.
- class setSwitchVector(root, device, client)¶
The remote driver is setting a Switch vector property. This is a mapping of membername:value.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.state
self.timeout
This could be None if no timeout information is included, in which case the existing timeout is not altered.
self.eventtype
Set to the string “Set”.
- class setTextVector(root, device, client)¶
The remote driver is setting a Text vector property. This is a mapping of membername:value.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.state
self.timeout
This could be None if no timeout information is included, in which case the existing timeout is not altered.
self.eventtype
Set to the string “Set”.
- class setNumberVector(root, device, client)¶
The remote driver is setting a Number vector property. This is a mapping of membername:value. These number values are string values.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.state
self.timeout
This could be None if no timeout information is included, in which case the existing timeout is not altered.
self.eventtype
Set to the string “Set”.
- class setLightVector(root, device, client)¶
The remote driver is setting a Light vector property. This is a mapping of membername:value. Note, the timeout attribute will always be None
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.state
self.timeout
This is None.
self.eventtype
Set to the string “Set”.
- class setBLOBVector(root, device, client)¶
The remote driver is setting a BLOB vector property. This is a mapping of membername:value, where value is a bytes object, taken from the received xml and b64 decoded This event has further attribute sizeformat being a dictionary of membername:(size, format) and which are then set into the target members as blobsize and blobformat attributes.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.root
self.timestamp
self.message
self.state
self.sizeformat
A dictionary of membername to tuple (membersize, memberformat)
self.timeout
This could be None if no timeout information is included, in which case the existing timeout is not altered.
self.eventtype
Set to the string “SetBLOB”.
The following events are not generated by received data, the first VectorTimeOut is generated automatically after a timeout, the second can be created by awaiting vector.create_clientevent
- class VectorTimeOut(device, vector)¶
This event is generated by a timeout, not by received data.
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.timestamp
This is created by datetime.now(tz=timezone.utc)
self.eventtype
Set to the string “TimeOut”.
- class ClientEvent(eventtype, device, vector, **payload)¶
This event is not generated by received data. It can be created programmatically by a client awaiting vector.create_clientevent(eventtype, **payload) This object is also a mapping of membername:value for the vectors contents
Attributes
self.device
self.devicename
self.vector
self.vectorname
self.timestamp
This is created by datetime.now(tz=timezone.utc)
self.eventtype
As default, “ClientEvent”, but can be set to any string when calling vector.create_clientevent
self.payload
A keyword arguments dictionary, set to any value desired when calling vector.create_clientevent
An example of using the create_clientevent method is at:
https://github.com/bernie-skipole/inditest/blob/main/docexamples/clientevent.py
- class ConnectionMade¶
This event is generated on connection, not by received data.
Attributes
self.device
This is None
self.devicename
This is None
self.vector
This is None
self.vectorname
This is None
self.timestamp
This is created by datetime.now(tz=timezone.utc)
self.eventtype
Set to the string “ConnectionMade”.
- class ConnectionLost¶
This event is generated on connection fail, not by received data.
Attributes
self.device
This is None
self.devicename
This is None
self.vector
This is None
self.vectorname
This is None
self.timestamp
This is created by datetime.now(tz=timezone.utc)
self.eventtype
Set to the string “ConnectionLost”.