Class: QgsAbstractSensor

An abstract base class for sensors.

Added in version 3.32.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: handleConnect(), handleDisconnect()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractSensor

Base classes

QObject

Subclasses

QgsIODeviceSensor

An abstract class for QIODevice-based sensors.

Abstract Methods

handleConnect

Handles the connection to the sensor.

handleDisconnect

Handles the disconnection from the sensor.

Methods

connectSensor

Connects the sensor to its source.

data

Returns the latest captured data from the sensor.

disconnectSensor

Disconnects the sensor from its source.

errorString

Returns the last error message.

id

Returns the sensor ID.

name

Returns the user-friendly name identifying the sensor.

readXml

Restores generic sensor details from a DOM element.

setData

Sets the latest captured data from the sensor.

setName

Sets the user-friendly name identfying the sensor.

setStatus

Sets the current sensor status.

status

Returns the current sensor status.

writeXml

Write generic sensor properties into a DOM element.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractSensor. See the FAQ for more details.

readPropertiesFromElement

Restores specific sensor type properties from a DOM element.

type

Returns the sensor type.

writePropertiesToElement

Write specific sensor type properties into a DOM element.

Signals

dataChanged

Emitted when the captured sensor data has changed.

errorOccurred

Emitted when an error has occurred.

nameChanged

Emitted when the sensor name has changed.

statusChanged

Emitted when the sensor status has changed.

class qgis.core.QgsAbstractSensor[source]

Bases: QObject

__init__(parent: QObject | None = None)

Constructor for an abstract sensor, bound to the specified parent.

Parameters:

parent (Optional[QObject] = None)

class SensorData

Bases: object

Contains details of a sensor data capture

lastTimestamp: QDateTime

Timestamp of last captured sensor value

lastValue: object

Last captured sensor value stored as a QVariant.

Note

The member can store multiple values if the sensor passes on a QVariantMap.

connectSensor(self)[source]

Connects the sensor to its source.

data(self) QgsAbstractSensor.SensorData[source]

Returns the latest captured data from the sensor.

Return type:

QgsAbstractSensor.SensorData

signal dataChanged[source]

Emitted when the captured sensor data has changed.

disconnectSensor(self)[source]

Disconnects the sensor from its source.

signal errorOccurred(errorString: str)[source]

Emitted when an error has occurred. The errorString describes the error.

Parameters:

errorString (str)

errorString(self) str[source]

Returns the last error message.

Return type:

str

abstract handleConnect(self)[source]

Handles the connection to the sensor.

Note

Triggered by calling connectSensor()

abstract handleDisconnect(self)[source]

Handles the disconnection from the sensor.

Note

Triggered by calling disconnectSensor()

id(self) str[source]

Returns the sensor ID.

Note

This is a autogenerated unique string identifying an individual sensor.

Return type:

str

name(self) str[source]

Returns the user-friendly name identifying the sensor.

Return type:

str

signal nameChanged[source]

Emitted when the sensor name has changed.

virtual readPropertiesFromElement(self, element: QDomElement, document: QDomDocument) bool[source]

Restores specific sensor type properties from a DOM element.

Parameters:
  • element (QDomElement) – DOM node corresponding to item (e.g. ‘Sensor’ element)

  • document (QDomDocument) – DOM document

Return type:

bool

readXml(self, element: QDomElement, document: QDomDocument) bool[source]

Restores generic sensor details from a DOM element.

Parameters:
  • element (QDomElement) – DOM node corresponding to item (e.g. ‘Sensor’ element)

  • document (QDomDocument) – DOM document

Return type:

bool

setData(self, data: QgsAbstractSensor.SensorData)[source]

Sets the latest captured data from the sensor.

Parameters:

data (QgsAbstractSensor.SensorData)

setName(self, name: str | None)[source]

Sets the user-friendly name identfying the sensor.

Parameters:

name (Optional[str])

setStatus(self, status: Qgis.DeviceConnectionStatus)[source]

Sets the current sensor status.

Parameters:

status (Qgis.DeviceConnectionStatus)

status(self) Qgis.DeviceConnectionStatus[source]

Returns the current sensor status.

Return type:

Qgis.DeviceConnectionStatus

signal statusChanged[source]

Emitted when the sensor status has changed.

virtual type(self) str[source]

Returns the sensor type. This will match the type string of the sensor class, as used by QgsSensorRegistry.

Return type:

str

virtual writePropertiesToElement(self, element: QDomElement, document: QDomDocument) bool[source]

Write specific sensor type properties into a DOM element.

Parameters:
  • element (QDomElement) – DOM node corresponding to item (e.g. ‘Sensor’ element)

  • document (QDomDocument) – DOM document

Return type:

bool

writeXml(self, parentElement: QDomElement, document: QDomDocument) bool[source]

Write generic sensor properties into a DOM element.

Parameters:
  • parentElement (QDomElement) – parent DOM element (e.g ‘Sensors’ element)

  • document (QDomDocument) – DOM document

Return type:

bool