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
19 changes: 19 additions & 0 deletions docs/source/Services/TagoTiP_Type.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**TagoTiP Type**
===================


.. _TagoTiPCommand:

TagoTiPCommand
--------------

**Attributes:**

| **serial**: str
| Serial of the target device

| **protocol**: str
| Protocol used to deliver the command

| **body**: str
| Command payload sent to the device
27 changes: 27 additions & 0 deletions docs/source/Services/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ Send SMS to phone number
"message": "Test",
}
)
=======
TagoTiP
=======

Send a command to a device through TagoTiP

Requires a Service Authorization token in the module token.

**Parameters:**

| **command**: :ref:`TagoTiPCommand`
| Command object with serial, protocol and body

.. code-block::
:caption: **Example:**

from tagoio_sdk import Services

services = Services({"token": "your-service-authorization-token"})
services.tagotip.cmd(
{
"serial": "mqtt1",
"protocol": "mqtt",
"body": "reboot-now",
}
)


.. toctree::
Expand All @@ -207,6 +233,7 @@ Send SMS to phone number
Notification_Type
Pdf_Type
SMS_Type
TagoTiP_Type



2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tagoio-sdk"
version = "5.1.4"
version = "5.1.5"
description = "Official Python SDK for TagoIO"
authors = [{name = "TagoIO Inc.", email = "contact@tago.io"}]
license = {text = "Apache-2.0"}
Expand Down
2 changes: 2 additions & 0 deletions src/tagoio_sdk/modules/Services/Services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tagoio_sdk.modules.Services.Notification import Notification
from tagoio_sdk.modules.Services.PDF import PDFService
from tagoio_sdk.modules.Services.SMS import SMS
from tagoio_sdk.modules.Services.TagoTiP import TagoTiP
from tagoio_sdk.params import get_params


Expand All @@ -23,3 +24,4 @@ def __init__(self, params: Optional[GenericModuleParams] = None):
self.Notification = Notification(self.params)
self.Attachment = Attachment(self.params)
self.PDF = PDFService(self.params)
self.tagotip = TagoTiP(self.params)
50 changes: 50 additions & 0 deletions src/tagoio_sdk/modules/Services/TagoTiP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from typing import TypedDict

from tagoio_sdk.common.tagoio_module import TagoIOModule


class TagoTiPCommand(TypedDict):
serial: str
"""
Serial of the target device
"""
protocol: str
"""
Protocol used to deliver the command
"""
body: str
"""
Command payload sent to the device
"""


class TagoTiP(TagoIOModule):
def cmd(self, command: TagoTiPCommand) -> str:
"""
Send a command to a device through TagoTiP.

Requires a Service Authorization token in the module `token`.

:param TagoTiPCommand command: Command object with serial, protocol and body

Example:
>>> from tagoio_sdk import Services
>>> services = Services({"token": "your-service-authorization-token"})
>>> services.tagotip.cmd({
... "serial": "mqtt1",
... "protocol": "mqtt",
... "body": "reboot-now",
... })
"""
result = self.doRequest(
{
"path": "/tip/cmd",
"method": "POST",
"body": {
"serial": command["serial"],
"protocol": command["protocol"],
"body": command["body"],
},
}
)
return result
32 changes: 32 additions & 0 deletions tests/Services/test_tagotip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

from requests_mock.mocker import Mocker

from tagoio_sdk.modules.Services.Services import Services


os.environ["T_ANALYSIS_TOKEN"] = "your_token_value"


def testTagoTiPCmd(requests_mock: Mocker) -> None:
"""Test cmd method of TagoTiP service."""
requests_mock.post(
"https://api.tago.io/tip/cmd", json={"status": True, "result": "ok"}
)

services = Services({"token": "your-service-authorization-token"})

result = services.tagotip.cmd(
{
"serial": "mqtt1",
"protocol": "mqtt",
"body": "reboot-now",
}
)

assert result == "ok"
assert requests_mock.last_request.json() == {
"serial": "mqtt1",
"protocol": "mqtt",
"body": "reboot-now",
}
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading