eta_utility.connectors.cumulocity module

class eta_utility.connectors.cumulocity.CumulocityConnection(url: str, usr: str | None, pwd: str | None, *, tenant: str, nodes: Nodes[NodeCumulocity] | None = None)[source]

Bases: SeriesConnection[NodeCumulocity]

CumulocityConnection is a class to download and upload multiple features from and to the Cumulocity database as timeseries.

Parameters:
  • url – URL of the server without scheme (https://).

  • usr – Username in Cumulocity for login.

  • pwd – Password in Cumulocity for login.

  • tenant – Cumulocity tenant.

  • nodes – Nodes to select in connection.

read(nodes: Nodes[NodeCumulocity] | None = None) pd.DataFrame[source]

Download current value from the Cumulocity Database

Parameters:

nodes – List of nodes to read values from.

Returns:

pandas.DataFrame containing the data read from the connection.

write(values: pd.Series[datetime, Any], measurement_type: str, unit: str, nodes: Nodes[NodeCumulocity] | None = None) None[source]

Write values to the cumulocity Database

Parameters:
  • values – Pandas Series containing the data. Make sure the index is a Datetimeindex. If fragment is not specified for node, make sure the pd.Series has name since it will be used as replacement.

  • measurement_type – The type of the measurement to be written.

  • unit – The unit of the values.

  • nodes – List of nodes to write values to.

subscribe(handler: SubscriptionHandler, nodes: Nodes[NodeCumulocity] | None = None, interval: TimeStep = 1) None[source]

Subscribe to nodes and call handler when new data is available. This will return only the last available values.

Parameters:
  • handler – SubscriptionHandler object with a push method that accepts node, value pairs.

  • interval – Interval for receiving new data. It is interpreted as seconds when given as an integer.

  • nodes – Identifiers for the nodes to subscribe to.

read_series(from_time: datetime, to_time: datetime, nodes: Nodes[NodeCumulocity] | None = None, interval: TimeStep | None = None, **kwargs: Any) pd.DataFrame[source]

Download timeseries data from the Cumulocity Database

Parameters:
  • nodes – List of nodes to read values from.

  • from_time – Starting time to begin reading.

  • to_time – Time to stop reading at.

  • interval – Interval between time steps. It is interpreted as seconds if given as integer (ignored by this connector).

  • kwargs – Other parameters (ignored by this connector).

Returns:

Pandas DataFrame containing the data read from the connection.

subscribe_series(handler: SubscriptionHandler, req_interval: TimeStep, offset: TimeStep | None = None, nodes: Nodes[NodeCumulocity] | None = None, interval: TimeStep = 1, data_interval: TimeStep = 1, **kwargs: Any) None[source]

Subscribe to nodes and call handler when new data is available. This will always return a series of values. If nodes with different intervals should be subscribed, multiple connection objects are needed.

Parameters:
  • handler – SubscriptionHandler object with a push method that accepts node, value pairs.

  • req_interval – Duration covered by requested data (time interval). Interpreted as seconds if given as int.

  • offset – Offset from datetime.now from which to start requesting data (time interval). Interpreted as seconds if given as int. Use negative values to go to past timestamps.

  • data_interval – Time interval between values in returned data. Interpreted as seconds if given as int.

  • interval – interval (between requests) for receiving new data. It is interpreted as seconds when given as an integer.

  • nodes – Identifiers for the nodes to subscribe to.

  • kwargs – Other, ignored parameters.

static create_device(url: str, username: str, password: str, tenant: str, device_name: str) None[source]

Create a cumulocity device.

Parameters:
  • url – URL of the server without scheme (https://).

  • usr – Username in Cumulocity for login.

  • pwd – Password in Cumulocity for login.

  • tenant – Cumulocity tenant.

  • device_name – Name of the to be created device.

static get_measurement_ids_by_device(url: str, username: str, password: str, tenant: str, device_id: str) list[source]

Returns a list of all measurement IDs that the specified device holds.

Parameters:
  • url – URL of the server without scheme (https://).

  • usr – Username in Cumulocity for login.

  • pwd – Password in Cumulocity for login.

  • tenant – Cumulocity tenant.

  • device_id – ID of the device to retrieve the measurement IDs from.

close_sub() None[source]

Close an open subscription.

timestr_from_datetime(dt: datetime) str[source]

Create an Cumulocity compatible time string.

Parameters:

dt – Datetime object to convert to string.

Returns:

Cumulocity compatible time string.

get_auth_header() dict[source]