From 8a9601ef3e176cb51806d1295b9f3b334d9eb874 Mon Sep 17 00:00:00 2001 From: Ricardo Stoklosa Date: Tue, 18 Aug 2026 17:05:59 -0300 Subject: [PATCH] feat(tagotip): move TagoTiP to a standalone top-level client Replace the Services.tagotip service (added in #67) with a standalone TagoTiP client constructed directly with a Service Authorization token and exported at the package top level. Services defaults its token to the analysis token, so TagoTiP must not live under it. Matches tago-io/sdk-js#185. --- docs/source/Services/index.rst | 27 ---------- .../{Services => TagoTiP}/TagoTiP_Type.rst | 2 +- docs/source/TagoTiP/index.rst | 54 +++++++++++++++++++ docs/source/index.rst | 1 + pyproject.toml | 2 +- src/tagoio_sdk/__init__.py | 3 +- src/tagoio_sdk/modules/Services/Services.py | 2 - .../modules/{Services => TagoTiP}/TagoTiP.py | 6 +-- tests/{Services => TagoTiP}/test_tagotip.py | 18 +++---- uv.lock | 2 +- 10 files changed, 69 insertions(+), 48 deletions(-) rename docs/source/{Services => TagoTiP}/TagoTiP_Type.rst (93%) create mode 100644 docs/source/TagoTiP/index.rst rename src/tagoio_sdk/modules/{Services => TagoTiP}/TagoTiP.py (87%) rename tests/{Services => TagoTiP}/test_tagotip.py (50%) diff --git a/docs/source/Services/index.rst b/docs/source/Services/index.rst index 2020b46..3e9bf2a 100644 --- a/docs/source/Services/index.rst +++ b/docs/source/Services/index.rst @@ -197,32 +197,6 @@ 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:: @@ -233,7 +207,6 @@ Requires a Service Authorization token in the module token. Notification_Type Pdf_Type SMS_Type - TagoTiP_Type diff --git a/docs/source/Services/TagoTiP_Type.rst b/docs/source/TagoTiP/TagoTiP_Type.rst similarity index 93% rename from docs/source/Services/TagoTiP_Type.rst rename to docs/source/TagoTiP/TagoTiP_Type.rst index 48ec321..38a1b00 100644 --- a/docs/source/Services/TagoTiP_Type.rst +++ b/docs/source/TagoTiP/TagoTiP_Type.rst @@ -1,5 +1,5 @@ **TagoTiP Type** -=================== +================ .. _TagoTiPCommand: diff --git a/docs/source/TagoTiP/index.rst b/docs/source/TagoTiP/index.rst new file mode 100644 index 0000000..7085fce --- /dev/null +++ b/docs/source/TagoTiP/index.rst @@ -0,0 +1,54 @@ +**TagoTiP** +=========== + +======== +Instance +======== + + **Parameters:** + + | **token**: str + | Service Authorization token. + + | *Optional* **region**: str "us-e1" or "ue-w1" or "env" + | Region is a optional parameter + +.. code-block:: + :caption: **Example:** + + from tagoio_sdk import TagoTiP + + tagotip = TagoTiP({"token": "your-service-authorization-token"}) + + +=== +cmd +=== + +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 TagoTiP + + tagotip = TagoTiP({"token": "your-service-authorization-token"}) + tagotip.cmd( + { + "serial": "mqtt1", + "protocol": "mqtt", + "body": "reboot-now", + } + ) + + +.. toctree:: + + TagoTiP_Type diff --git a/docs/source/index.rst b/docs/source/index.rst index 50471cf..90c90ac 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -277,6 +277,7 @@ API Reference Resources/index Device/index Services/index + TagoTiP/index Utils/index .. toctree:: diff --git a/pyproject.toml b/pyproject.toml index 8048669..9c9f6d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "tagoio-sdk" -version = "5.1.5" +version = "5.1.6" description = "Official Python SDK for TagoIO" authors = [{name = "TagoIO Inc.", email = "contact@tago.io"}] license = {text = "Apache-2.0"} diff --git a/src/tagoio_sdk/__init__.py b/src/tagoio_sdk/__init__.py index f64b3f3..18d9049 100644 --- a/src/tagoio_sdk/__init__.py +++ b/src/tagoio_sdk/__init__.py @@ -5,6 +5,7 @@ from .modules.Resources.AccountDeprecated import AccountDeprecated as Account from .modules.Resources.Resources import Resources from .modules.Services.Services import Services +from .modules.TagoTiP.TagoTiP import TagoTiP -__all__ = ["Analysis", "Device", "Account", "Resources", "Services"] +__all__ = ["Analysis", "Device", "Account", "Resources", "Services", "TagoTiP"] diff --git a/src/tagoio_sdk/modules/Services/Services.py b/src/tagoio_sdk/modules/Services/Services.py index 6b8d53a..60109b9 100644 --- a/src/tagoio_sdk/modules/Services/Services.py +++ b/src/tagoio_sdk/modules/Services/Services.py @@ -9,7 +9,6 @@ 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 @@ -24,4 +23,3 @@ 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) diff --git a/src/tagoio_sdk/modules/Services/TagoTiP.py b/src/tagoio_sdk/modules/TagoTiP/TagoTiP.py similarity index 87% rename from src/tagoio_sdk/modules/Services/TagoTiP.py rename to src/tagoio_sdk/modules/TagoTiP/TagoTiP.py index d4ae113..84f7794 100644 --- a/src/tagoio_sdk/modules/Services/TagoTiP.py +++ b/src/tagoio_sdk/modules/TagoTiP/TagoTiP.py @@ -28,9 +28,9 @@ def cmd(self, command: TagoTiPCommand) -> str: :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({ + >>> from tagoio_sdk import TagoTiP + >>> tagotip = TagoTiP({"token": "your-service-authorization-token"}) + >>> tagotip.cmd({ ... "serial": "mqtt1", ... "protocol": "mqtt", ... "body": "reboot-now", diff --git a/tests/Services/test_tagotip.py b/tests/TagoTiP/test_tagotip.py similarity index 50% rename from tests/Services/test_tagotip.py rename to tests/TagoTiP/test_tagotip.py index 125c64f..0f4c771 100644 --- a/tests/Services/test_tagotip.py +++ b/tests/TagoTiP/test_tagotip.py @@ -1,22 +1,15 @@ -import os - from requests_mock.mocker import Mocker -from tagoio_sdk.modules.Services.Services import Services - - -os.environ["T_ANALYSIS_TOKEN"] = "your_token_value" +from tagoio_sdk import TagoTiP 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"} - ) + """Test cmd method of TagoTiP client.""" + requests_mock.post("https://api.tago.io/tip/cmd", json={"status": True, "result": "ok"}) - services = Services({"token": "your-service-authorization-token"}) + tagotip = TagoTiP({"token": "your-service-authorization-token"}) - result = services.tagotip.cmd( + result = tagotip.cmd( { "serial": "mqtt1", "protocol": "mqtt", @@ -30,3 +23,4 @@ def testTagoTiPCmd(requests_mock: Mocker) -> None: "protocol": "mqtt", "body": "reboot-now", } + assert requests_mock.last_request.headers["token"] == "your-service-authorization-token" diff --git a/uv.lock b/uv.lock index ca1646c..acb62c9 100644 --- a/uv.lock +++ b/uv.lock @@ -421,7 +421,7 @@ wheels = [ [[package]] name = "tagoio-sdk" -version = "5.1.5" +version = "5.1.6" source = { editable = "." } dependencies = [ { name = "python-dateutil" },