-
Notifications
You must be signed in to change notification settings - Fork 2
test(drivers): let a driver report metrics, and a topic carry a configurable prefix #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,22 +37,36 @@ def test_subscribes_in_driver_init(self, driver_name): | |
| f"not elsewhere" | ||
| ) | ||
|
|
||
| def test_subscription_topics_are_strings(self, driver_name): | ||
| """All mqtt_subscribe calls should use string literal topics.""" | ||
| def test_subscription_topics_are_static(self, driver_name): | ||
| """A subscription topic must be decidable without running the driver. | ||
|
|
||
| A literal is the common case. A configurable prefix is the other one: | ||
| heishamon and ctek_hybrid both build the topic from a file-local set | ||
| in driver_init, because the broker prefix is the operator's to choose. | ||
| That stays reviewable — every part is in the file. | ||
|
|
||
| What this rejects is a topic taken from runtime data: an index, a | ||
| field or a call, which is how a driver ends up subscribing to whatever | ||
| a message told it to. | ||
| """ | ||
| code = read_driver(driver_name) | ||
| clean = strip_lua_comments(code) | ||
|
|
||
| # Find all subscribe calls and verify they use string literals | ||
| sub_calls = re.findall( | ||
| r'host\.mqtt_subscribe\s*\(\s*(.+?)\s*\)', | ||
| clean, | ||
| ) | ||
|
|
||
| for call_arg in sub_calls: | ||
| # Should be a string literal (starts with ") | ||
| assert call_arg.strip().startswith('"'), ( | ||
| f"{driver_name}: mqtt_subscribe should use string literal " | ||
| f"topic, found: {call_arg}" | ||
| arg = call_arg.strip() | ||
| static = re.fullmatch( | ||
| r'(?:"[^"]*"|[A-Za-z_]\w*)' | ||
| r'(?:\s*\.\.\s*(?:"[^"]*"|[A-Za-z_]\w*))*', | ||
|
Comment on lines
+63
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a driver assigns runtime data to a temporary, such as Useful? React with 👍 / 👎. |
||
| arg, | ||
| ) | ||
| assert static, ( | ||
| f"{driver_name}: mqtt_subscribe topic must be a literal or a " | ||
| f"concatenation of literals and file-local names, found: {arg}" | ||
| ) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a meter, PV, battery, or other schema-backed driver accidentally removes its
host.emit()call but retains any diagnostichost.emit_metric()call, this assertion now passes even though the driver emits no DER telemetry.spec/driver-contract.mdrequires polling to emit telemetry viahost.emit(), whilespec/host-api.mdexplicitly defines metrics as diagnostics outside the DER telemetry schema, so the metric-only exception should be limited to heat-pump/schema-less drivers rather than weakening the contract for every driver.Useful? React with 👍 / 👎.