not using shim

This commit is contained in:
2026-02-12 11:01:52 -06:00
parent f3c159913e
commit 9de5097061
3 changed files with 44 additions and 46 deletions

View File

@@ -3,19 +3,23 @@
Hello Action - Python Example Pack Hello Action - Python Example Pack
A minimal Python action that returns "Hello, Python". A minimal Python action that returns "Hello, Python".
Demonstrates the basic structure of a Python action in Attune. Demonstrates the basic structure of a self-contained action in Attune.
Actions receive parameters as JSON on stdin and write results to stdout.
""" """
import json import json
import sys import sys
def run(**kwargs): def main():
"""Return a simple greeting message.""" # Read parameters from stdin (JSON format)
return {"message": "Hello, Python"} params = json.loads(sys.stdin.readline())
name = params.get("name", "Python")
result = {"message": f"Hello, {name}"}
print(json.dumps(result))
if __name__ == "__main__": if __name__ == "__main__":
result = run() main()
print(json.dumps({"result": result, "status": "success"}))
sys.exit(0)

View File

@@ -3,20 +3,34 @@
HTTP Example Action - Python Example Pack HTTP Example Action - Python Example Pack
Demonstrates using the `requests` library to make an HTTP call to example.com. Demonstrates using the `requests` library to make an HTTP call to example.com.
Receives parameters via stdin JSON (through the Python wrapper). Receives parameters via stdin as JSON.
""" """
import requests import json
import sys
import urllib.request
def run(url="https://example.com", **kwargs): def main():
"""Fetch a URL and return status and a snippet of the response body.""" # Read parameters from stdin (JSON format)
response = requests.get(url, timeout=10) params = json.loads(sys.stdin.readline())
url = params.get("url", "https://example.com")
return { req = urllib.request.Request(url)
"status_code": response.status_code, with urllib.request.urlopen(req, timeout=10) as response:
"url": response.url, text = response.read().decode("utf-8")
"content_length": len(response.text), status_code = response.status
"snippet": response.text[:500], final_url = response.url
"success": response.ok,
result = {
"status_code": status_code,
"url": final_url,
"content_length": len(text),
"snippet": text[:500],
"success": 200 <= status_code < 400,
} }
print(json.dumps(result))
if __name__ == "__main__":
main()

View File

@@ -5,46 +5,26 @@ Read Counter Action - Python Example Pack
Consumes a counter value (typically from the counter sensor trigger payload) Consumes a counter value (typically from the counter sensor trigger payload)
and returns a formatted message containing the counter value. and returns a formatted message containing the counter value.
Parameters are delivered via stdin as JSON from the Python wrapper. Parameters are delivered via stdin as JSON.
""" """
import json import json
import sys import sys
def run(counter=0, rule_ref="unknown", **kwargs): def main():
"""Return a message containing the counter value. # Read parameters from stdin (JSON format)
params = json.loads(sys.stdin.readline())
Args: counter = params.get("counter", 0)
counter: The counter value from the trigger payload. rule_ref = params.get("rule_ref", "unknown")
rule_ref: The rule reference that produced this counter.
**kwargs: Additional parameters (ignored).
Returns: result = {
dict with a formatted message and the raw counter value.
"""
return {
"message": f"Counter value is {counter} (from rule: {rule_ref})", "message": f"Counter value is {counter} (from rule: {rule_ref})",
"counter": counter, "counter": counter,
"rule_ref": rule_ref, "rule_ref": rule_ref,
} }
print(json.dumps(result))
def main():
"""Entry point when run directly (without the Python wrapper)."""
try:
content = sys.stdin.read().strip()
if content:
parts = content.split("---ATTUNE_PARAMS_END---")
params = json.loads(parts[0].strip()) if parts[0].strip() else {}
else:
params = {}
except (json.JSONDecodeError, IndexError):
params = {}
result = run(**params)
print(json.dumps(result, indent=2))
sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":