Initial commit: Python Example Pack for Attune
Includes: - 3 Python actions (hello, http_example, read_counter) - 1 counter trigger type - 1 counter sensor (Python, keystore-backed, per-rule state) - 1 example rule (count_and_log) - requirements.txt with requests and pika - README with full usage documentation
This commit is contained in:
75
sensors/counter_sensor.yaml
Normal file
75
sensors/counter_sensor.yaml
Normal file
@@ -0,0 +1,75 @@
|
||||
# Counter Sensor
|
||||
# Emits incrementing counter events, storing state in the Attune keystore
|
||||
#
|
||||
# Each subscribing rule gets its own independent counter, keyed by rule ref.
|
||||
# The sensor listens for rule lifecycle events via RabbitMQ and manages
|
||||
# per-rule timer loops that emit one event per second (configurable).
|
||||
|
||||
ref: python_example.counter_sensor
|
||||
label: "Counter Sensor"
|
||||
description: "Emits periodic counter events with per-rule state stored in the Attune keystore"
|
||||
enabled: true
|
||||
|
||||
# Sensor runner type
|
||||
runner_type: python
|
||||
|
||||
# Entry point for sensor execution
|
||||
entry_point: counter_sensor.py
|
||||
|
||||
# Trigger types this sensor monitors
|
||||
trigger_types:
|
||||
- python_example.counter
|
||||
|
||||
# Sensor configuration schema
|
||||
parameters:
|
||||
type: object
|
||||
properties:
|
||||
default_interval_seconds:
|
||||
type: integer
|
||||
description: "Default interval between counter emissions (in seconds)"
|
||||
default: 1
|
||||
minimum: 1
|
||||
maximum: 3600
|
||||
key_prefix:
|
||||
type: string
|
||||
description: "Prefix for counter keys in the Attune keystore"
|
||||
default: "python_example.counter"
|
||||
|
||||
# Poll interval (how often the sensor checks for events)
|
||||
poll_interval: 1
|
||||
|
||||
# Tags for categorization
|
||||
tags:
|
||||
- counter
|
||||
- python
|
||||
- example
|
||||
- keystore
|
||||
|
||||
# Metadata
|
||||
meta:
|
||||
builtin: false
|
||||
system: false
|
||||
description: |
|
||||
The counter sensor demonstrates a stateful Python sensor that integrates
|
||||
with the Attune keystore. It maintains a separate monotonically-increasing
|
||||
counter for each subscribing rule, persisting the value in the keystore
|
||||
so that counters survive sensor restarts.
|
||||
|
||||
Features exercised:
|
||||
- Python sensor lifecycle (startup, rule subscription, shutdown)
|
||||
- RabbitMQ integration for rule lifecycle events
|
||||
- Attune keystore API for persistent state (GET/PUT/POST /api/v1/keys)
|
||||
- Per-rule scoped state via keystore key naming
|
||||
- Periodic event emission via POST /events API
|
||||
- Graceful shutdown with thread cleanup
|
||||
|
||||
# Documentation
|
||||
examples:
|
||||
- description: "Counter firing every second (default)"
|
||||
trigger_type: python_example.counter
|
||||
trigger_config: {}
|
||||
|
||||
- description: "Counter firing every 5 seconds"
|
||||
trigger_type: python_example.counter
|
||||
trigger_config:
|
||||
interval_seconds: 5
|
||||
Reference in New Issue
Block a user