Skip to content

Commit eaaee22

Browse files
committed
docs(resources): document the MQTT Endpoint paid plan and optional mqtt
Make mqtt NotRequired on AnalysisInfo, since servers without the MQTT Endpoint do not return it. Document the paid plan gate and its refusal message, and that mqtt events are opt-in and off by default.
1 parent a1ff209 commit eaaee22

7 files changed

Lines changed: 65 additions & 20 deletions

File tree

‎docs/source/Resources/Analysis/Analysis_Type.rst‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ AnalysisInfo(:ref:`AnalysisCreateInfo`)
7070
7171
| console: Optional[List[str]]
7272
73-
| mqtt: Optional[:ref:`AnalysisMqtt`]
74-
| MQTT Endpoint state. Returned by info, not by list.
73+
| mqtt: NotRequired[:ref:`AnalysisMqtt`]
74+
| MQTT Endpoint state. Returned by info, not by list. Absent on servers without the MQTT Endpoint, such as older TagoDeploy instances.
7575
7676

7777
.. _AnalysisMqttEvents:
@@ -80,18 +80,18 @@ AnalysisMqttEvents
8080
------------------
8181

8282
Session events of the MQTT Endpoint that also run the code; a PUBLISH always runs it.
83-
info returns all three keys; create and edit accept any subset.
83+
Each event is opt-in and off by default. info returns all three keys; create and edit accept any subset.
8484

8585
**Attributes:**
8686

8787
| connect: bool
88-
| Run the code when a device connects. Default False.
88+
| Run the code when a device connects. Off by default.
8989
9090
| subscribe: bool
91-
| Run the code once per filter when a device subscribes. Default False.
91+
| Run the code once per filter when a device subscribes. Off by default.
9292
9393
| unsubscribe: bool
94-
| Run the code once per filter when a device unsubscribes. Default False.
94+
| Run the code once per filter when a device unsubscribes. Off by default.
9595
9696

9797
.. _AnalysisMqttPorts:
@@ -116,11 +116,14 @@ AnalysisMqttChanges
116116
-------------------
117117

118118
MQTT Endpoint settings on create and edit. Edit merges them into the stored settings.
119+
Turning the MQTT Endpoint or an event on needs a paid plan (Lite, Pro, or Max; TagoDeploy instances are not gated).
120+
On a Free account the request is refused with "The MQTT Endpoint needs a paid plan. Upgrade to use it.";
121+
turning things off is always allowed.
119122

120123
**Attributes:**
121124

122125
| active: Optional[bool]
123-
| Turns the MQTT Endpoint on or off. Luau Analyses only.
126+
| Turns the MQTT Endpoint on or off. Luau Analyses only. Off by default.
124127
125128
| events: Optional[:ref:`AnalysisMqttEvents`]
126129
| Session events to turn on or off.

‎docs/source/Resources/Analysis/index.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ tryMqtt
204204

205205
Runs the MQTT Endpoint of a Luau Analysis once for a test message, as a device publish would.
206206
The MQTT Endpoint must be on and the Analysis active. ``Mqtt.publish`` calls from the run reach
207-
connected devices. Each call counts against the MQTT Endpoint run limit. The MQTT Endpoint needs a paid plan.
207+
connected devices. Each call counts against the MQTT Endpoint run limit.
208+
The MQTT Endpoint needs a paid plan (Lite, Pro, or Max; TagoDeploy instances are not gated);
209+
on a Free account the call is refused with "The MQTT Endpoint needs a paid plan. Upgrade to use it."
208210

209211
See: `Analysis <https://docs.tago.io/docs/tagoio/analysis/>`_
210212

‎docs/source/Resources/ServiceAuthorization/Service_Authorization_Types.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ServiceAuthorizationCreateInfo(:ref:`CommonTokenData`)
1919
**Attributes:**
2020

2121
| analysis: Optional[:ref:`GenericID`]
22-
| [Optional] Luau Analysis whose MQTT Endpoint this authorization connects devices to. Set at creation only; it cannot change later.
22+
| [Optional] Luau Analysis whose MQTT Endpoint this authorization connects devices to. Set at creation only; it cannot change later. Needs a paid plan (Lite, Pro, or Max; TagoDeploy instances are not gated); on a Free account the request is refused with "The MQTT Endpoint needs a paid plan. Upgrade to use it."
2323
2424

2525
.. _TokenCreateResponseAuthorization:

‎src/tagoio_sdk/modules/Resources/Analyses.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ def tryMqtt(self, analysisID: GenericID, message: AnalysisMqttTry) -> AnalysisMq
234234
@description:
235235
Runs the MQTT Endpoint of a Luau Analysis once for a test message, as a device publish would.
236236
The MQTT Endpoint must be on and the Analysis active. Mqtt.publish calls from the run reach
237-
connected devices. Each call counts against the MQTT Endpoint run limit. The MQTT Endpoint
238-
needs a paid plan.
237+
connected devices. Each call counts against the MQTT Endpoint run limit.
238+
The MQTT Endpoint needs a paid plan (Lite, Pro, or Max; TagoDeploy instances are not gated);
239+
on a Free account the call is refused with "The MQTT Endpoint needs a paid plan. Upgrade to use it."
239240
240241
@see:
241242
https://docs.tago.io/docs/tagoio/analysis/ Analysis

‎src/tagoio_sdk/modules/Resources/Analysis_Types.py‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict
44
from typing import List
55
from typing import Literal
6+
from typing import NotRequired
67
from typing import Optional
78
from typing import TypedDict
89
from typing import Union
@@ -24,15 +25,16 @@ class ScriptFile(TypedDict):
2425
class AnalysisMqttEvents(TypedDict, total=False):
2526
"""
2627
Session events of the MQTT Endpoint that also run the code; a PUBLISH always runs it.
27-
info returns all three keys; create and edit accept any subset.
28+
Each event is opt-in and off by default. info returns all three keys; create and edit
29+
accept any subset.
2830
"""
2931

3032
connect: bool
31-
"""Run the code when a device connects. Default False."""
33+
"""Run the code when a device connects. Off by default."""
3234
subscribe: bool
33-
"""Run the code once per filter when a device subscribes. Default False."""
35+
"""Run the code once per filter when a device subscribes. Off by default."""
3436
unsubscribe: bool
35-
"""Run the code once per filter when a device unsubscribes. Default False."""
37+
"""Run the code once per filter when a device unsubscribes. Off by default."""
3638

3739

3840
class AnalysisMqttPorts(TypedDict):
@@ -45,10 +47,15 @@ class AnalysisMqttPorts(TypedDict):
4547

4648

4749
class AnalysisMqttChanges(TypedDict, total=False):
48-
"""MQTT Endpoint settings on create and edit. Edit merges them into the stored settings."""
50+
"""
51+
MQTT Endpoint settings on create and edit. Edit merges them into the stored settings.
52+
Turning the MQTT Endpoint or an event on needs a paid plan (Lite, Pro, or Max; TagoDeploy
53+
instances are not gated). On a Free account the request is refused with "The MQTT Endpoint
54+
needs a paid plan. Upgrade to use it."; turning things off is always allowed.
55+
"""
4956

5057
active: bool
51-
"""Turns the MQTT Endpoint on or off. Luau Analyses only."""
58+
"""Turns the MQTT Endpoint on or off. Luau Analyses only. Off by default."""
5259
events: AnalysisMqttEvents
5360
"""Session events to turn on or off."""
5461

@@ -109,8 +116,11 @@ class AnalysisInfo(AnalysisCreateInfo):
109116
updated_at: datetime
110117
locked_at: Any
111118
console: Optional[List[str]]
112-
mqtt: Optional[AnalysisMqtt]
113-
"""MQTT Endpoint state. Returned by info, not by list."""
119+
mqtt: NotRequired[AnalysisMqtt]
120+
"""
121+
MQTT Endpoint state. Returned by info, not by list. Absent on servers without the MQTT
122+
Endpoint, such as older TagoDeploy instances.
123+
"""
114124

115125

116126
class AnalysisQuery(Query):

‎src/tagoio_sdk/modules/Resources/Service_Authorization_Types.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class ServiceAuthorizationCreateInfo(TokenData, total=False):
1717
analysis: Optional[GenericID]
1818
"""
1919
[Optional] Luau Analysis whose MQTT Endpoint this authorization connects devices to.
20-
Set at creation only; it cannot change later.
20+
Set at creation only; it cannot change later. Needs a paid plan (Lite, Pro, or Max;
21+
TagoDeploy instances are not gated); on a Free account the request is refused with
22+
"The MQTT Endpoint needs a paid plan. Upgrade to use it."
2123
"""
2224

2325

‎tests/Resources/test_analyses.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,30 @@ def testAnalysesMethodCreateLuauWithMqtt(requests_mock: Mocker) -> None:
397397
"runtime": "luau-rt2026",
398398
"mqtt": {"active": True},
399399
}
400+
401+
402+
def testAnalysesMethodInfoWithoutMqtt(requests_mock: Mocker) -> None:
403+
"""A server without the MQTT Endpoint returns no mqtt field."""
404+
requests_mock.get(
405+
"https://api.tago.io/analysis/analysis_id", json=mockAnalysisInfo()
406+
)
407+
408+
resources = Resources()
409+
response = resources.analysis.info("analysis_id")
410+
411+
assert "mqtt" not in response
412+
413+
414+
def testAnalysesMethodTryMqttPaidPlan(requests_mock: Mocker) -> None:
415+
"""A Free account is refused with the paid plan message."""
416+
paid_plan = "The MQTT Endpoint needs a paid plan. Upgrade to use it."
417+
requests_mock.post(
418+
"https://api.tago.io/analysis/analysis_id/mqtt/try",
419+
status_code=400,
420+
json={"status": False, "message": paid_plan},
421+
)
422+
423+
resources = Resources()
424+
425+
with pytest.raises(TagoIORequestError, match="needs a paid plan"):
426+
resources.analysis.tryMqtt("analysis_id", {"topic": "sensors/42", "payload": "on"})

0 commit comments

Comments
 (0)