Save Signals

pyclarify.client.Client.save_signals(input_ids: List[pyclarify.fields.constraints.ConstrainedStrValue] = [], signals: List[pyclarify.views.signals.Signal] = [], signals_by_input: Dict[pyclarify.fields.constraints.ConstrainedStrValue, pyclarify.views.signals.Signal] = {}, create_only: bool = False, integration: str = None) pyclarify.views.generics.Response

This call inserts metadata to one or multiple signals. The signals are uniquely identified by its INPUT_ID. Mirroring the Clarify API call integration.saveSignals .

Parameters
  • input_ids (List['INPUT_ID']) – List of strings to be the input ID of the signal. Click here for more information.

  • signals (List[Signal]) – List of Signal object that contains metadata for a signal. Click here for more information.

  • create_only (bool, default False) – If set to true, skip update of information for existing signals. That is, all Input_ID’s that map to existing signals are silently ignored.

  • integration (str, default None) – Integration ID in string format. None means using the integration in credential file.

Returns

Response.result.data is a dictionary mapping INPUT_ID to SIGNAL_ID.

Return type

Response

Examples

>>> client = Client("./clarify-credentials.json")

Saving by using a dictionary.

>>> from pyclarify import Signal
>>> signal = Signal(
...     name = "Home temperature",
...     description = "Temperature in the bedroom",
...     labels = {
...         "data-source": ["Raspberry Pi"],
...         "location": ["Home"]
...     }
... )
>>> input_dict = {
...     "<INPUT_ID>" : signal
... }
>>> response = client.save_signals(
...     signals_by_input=input_dict
... )

Saving using arrays.

>>> from pyclarify import Signal
>>> signal = Signal(
...    name = "Home temperature",
...    description = "Temperature in the bedroom",
...    labels = {"data-source": ["Raspberry Pi"], "location": ["Home"]}
... )
>>> client.save_signals(input_ids=['INPUT_ID'], signals=[signal], create_only=False)
Response

In case of a valid return value, returns a pydantic model with the following format:

>>> jsonrpc = '2.0'
... id = '1'
... result = SaveSignalsResponse(
...             signalsByInput={
...                 'INPUT_ID': SaveSummary(id='SIGNAL_ID', created=True, updated=False)
...              }
...          )
... error = None

In case of the error the method return a pydantic model with the following format:

>>> jsonrpc = '2.0'
... id = '1'
... result = None
... error = Error(
...         code = '-32602',
...         message = 'Invalid params',
...         data = ErrorData(trace = <trace_id>, params = {})
... )