Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/source/Resources/Devices/Devices_Type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ DeviceCreateInfoBasicMutable



.. _DeviceCreateInfoBasicImutable:
.. _DeviceCreateInfoBasicImmutable:

DeviceCreateInfoBasicImutable
DeviceCreateInfoBasicImmutable
--------------------------------

**Attributes:**
Expand All @@ -281,7 +281,7 @@ DeviceCreateInfoBasicImutable
| **network**: :ref:`GenericID`
| Network ID.

| **type**: "imutable"
| **type**: "immutable"
| Device's data storage (bucket) type.
| :default: "legacy"

Expand Down Expand Up @@ -332,7 +332,7 @@ DeviceCreateInfoMutable
DeviceCreateInfoImmutable
--------------------------

**DeviceCreateInfoImmutable** = DeviceCreateInfoBasicImutable
**DeviceCreateInfoImmutable** = DeviceCreateInfoBasicImmutable


.. _DeviceCreateInfo:
Expand Down
2 changes: 1 addition & 1 deletion src/tagoio_sdk/modules/Resources/Buckets_Type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tagoio_sdk.common.Common_Type import TagsObj


DataStorageType = Literal["immutable", "mutable", "legacy"]
DataStorageType = Literal["immutable", "mutable", "legacy", "hybrid"]


class ExportBucketOption(TypedDict):
Expand Down
112 changes: 108 additions & 4 deletions src/tagoio_sdk/modules/Resources/Device_Type.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class DeviceInfo(TypedDict):
"""
Date for the device's last data retention.
"""
mutable_variable_regex: str or None
"""
Regex that routes each variable to the mutable side at insert time (unanchored substring match).

It must not match every variable or no variable; use a mutable or immutable device for those cases.

Present for Hybrid devices. Can only be changed while the device is empty.
"""


class DeviceInfoList(TypedDict):
Expand Down Expand Up @@ -270,7 +278,74 @@ class DeviceCreateInfoBasicMutable(TypedDict):
"""


class DeviceCreateInfoBasicImutable(TypedDict):
class DeviceCreateInfoBasicImmutable(TypedDict):
name: str
"""
Device name.
"""
connector: GenericID
"""
Connector ID.
"""
network: GenericID
"""
Network ID.
"""
type: Literal["immutable"]
"""
Device's data storage (bucket) type.

:default: "legacy"
"""
description: str or None
"""
Description of the device.
"""
active: bool
"""
Set if the device will be active.
"""
visible: bool
"""
Set if the device will be visible.
"""
configuration_params: list[ConfigurationParams]
"""
An array of configuration params
"""
tags: list[TagsObj]
"""
An array of tags
"""
serie_number: str
"""
Device serial number.
"""
connector_parse: bool
"""
If device will use connector parser
"""
parse_function: str
"""
Javascript code for use as payload parser
"""
chunk_period: Literal["day", "week", "month", "quarter"]
"""
Chunk division to retain data in the device.

Required for Immutable devices.
"""
chunk_retention: Union[int, float]
"""
Amount of chunks to retain data according to the `chunk_period`.

Integer between in the range of 0 to 36 (inclusive).

Required for Immutable devices.
"""


class DeviceCreateInfoBasicHybrid(TypedDict):
name: str
"""
Device name.
Expand All @@ -283,7 +358,7 @@ class DeviceCreateInfoBasicImutable(TypedDict):
"""
Network ID.
"""
type: Literal["imutable"]
type: Literal["hybrid"]
"""
Device's data storage (bucket) type.

Expand Down Expand Up @@ -335,13 +410,25 @@ class DeviceCreateInfoBasicImutable(TypedDict):

Required for Immutable devices.
"""
mutable_variable_regex: str
"""
Regex that routes each variable to the mutable side at insert time (unanchored substring match).

It must not match every variable or no variable; use a mutable or immutable device for those cases.

Required for Hybrid devices. Can only be changed while the device is empty.
"""


DeviceCreateInfoMutable = DeviceCreateInfoBasicMutable

DeviceCreateInfoImmutable = DeviceCreateInfoBasicImutable
DeviceCreateInfoImmutable = DeviceCreateInfoBasicImmutable

DeviceCreateInfoHybrid = DeviceCreateInfoBasicHybrid

DeviceCreateInfo = DeviceCreateInfoMutable or DeviceCreateInfoImmutable
DeviceCreateInfo = (
DeviceCreateInfoMutable or DeviceCreateInfoImmutable or DeviceCreateInfoHybrid
)


class DeviceEditInfo(TypedDict):
Expand Down Expand Up @@ -397,11 +484,28 @@ class DeviceEditInfo(TypedDict):

Required for Immutable devices.
"""
mutable_variable_regex: Optional[str]
"""
Regex that routes each variable to the mutable side at insert time (unanchored substring match).

It must not match every variable or no variable; use a mutable or immutable device for those cases.

Required for Hybrid devices. Can only be changed while the device is empty.
"""


DeviceEditInfo = DeviceEditInfo


class DeviceEmptyParams(TypedDict, total=False):
route: Literal["mutable", "immutable"]
"""
For Hybrid devices only: empty a single side of the device instead of everything.
"mutable" truncates the editable variables; "immutable" drops the telemetry chunks.
Omit to remove all data (every device type).
"""


class TokenData(TypedDict):
name: str
"""
Expand Down
6 changes: 5 additions & 1 deletion src/tagoio_sdk/modules/Resources/Devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from tagoio_sdk.modules.Resources.Device_Type import DeviceDataBackupResponse
from tagoio_sdk.modules.Resources.Device_Type import DeviceDataRestore
from tagoio_sdk.modules.Resources.Device_Type import DeviceEditInfo
from tagoio_sdk.modules.Resources.Device_Type import DeviceEmptyParams
from tagoio_sdk.modules.Resources.Device_Type import DeviceListItem
from tagoio_sdk.modules.Resources.Device_Type import DeviceQuery
from tagoio_sdk.modules.Resources.Device_Type import DeviceTokenDataList
Expand Down Expand Up @@ -451,10 +452,12 @@ def getDeviceData(self, deviceID: GenericID, queryParams: DataQuery = None) -> l
)
return dateParserList(result, ["time", "created_at"])

def emptyDeviceData(self, deviceID: GenericID) -> str:
def emptyDeviceData(self, deviceID: GenericID, params: Optional[DeviceEmptyParams] = None) -> str:
"""
@description:
Permanently removes all data from a device. This operation cannot be undone.
On Hybrid devices, pass params with route "mutable" or "immutable" to empty a
single side; omit it to remove all data.

@see:
https://help.tago.io/portal/en/kb/articles/device-data Device Data Management
Expand All @@ -471,6 +474,7 @@ def emptyDeviceData(self, deviceID: GenericID) -> str:
{
"path": f"/device/{deviceID}/empty",
"method": "POST",
"body": params,
}
)
return result
Expand Down
15 changes: 15 additions & 0 deletions tests/Resources/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,21 @@ def testEmptyDeviceData(requests_mock: Mocker) -> None:
assert result == "All data removed"


def testEmptyDeviceDataWithRoute(requests_mock: Mocker) -> None:
"""Test emptyDeviceData with the hybrid route param in the request body."""
device_id = "device-id-123"
requests_mock.post(
f"https://api.tago.io/device/{device_id}/empty",
json={"status": True, "result": "All data removed"},
)

resources = Resources({"token": "your_token_value"})
result = resources.devices.emptyDeviceData(device_id, {"route": "mutable"})

assert result == "All data removed"
assert requests_mock.last_request.json() == {"route": "mutable"}


def testAmount(requests_mock: Mocker) -> None:
"""Test amount method of Devices class."""
device_id = "device-id-123"
Expand Down
Loading