Refactor tracing: Move trace support to its own integration#48224
Refactor tracing: Move trace support to its own integration#48224emontnemery merged 1 commit intohome-assistant:devfrom
Conversation
d1c43f6 to
0519236
Compare
0519236 to
3617c0a
Compare
|
|
||
| from homeassistant.core import Context, HomeAssistant, callback | ||
| from homeassistant.helpers.json import JSONEncoder as HAJSONEncoder | ||
| from homeassistant.components.trace.const import DATA_TRACE, STORED_TRACES |
There was a problem hiding this comment.
I don't think that we should allow other integrations to be aware of hass.data[DATA_TRACE]. We should abstract that.
| automation_traces = hass.data[DATA_TRACE] | ||
| if unique_id not in automation_traces: | ||
| automation_traces[unique_id] = LimitedSizeDict(size_limit=STORED_TRACES) | ||
| automation_traces[unique_id][automation_trace.run_id] = automation_trace |
There was a problem hiding this comment.
We should abstract away how traces are stored from automation and script integrations.
| automation_traces = hass.data[DATA_TRACE] | |
| if unique_id not in automation_traces: | |
| automation_traces[unique_id] = LimitedSizeDict(size_limit=STORED_TRACES) | |
| automation_traces[unique_id][automation_trace.run_id] = automation_trace | |
| async_store_trace(hass, DOMAIN, automation_trace) |
async_store_trace would be a helper from trace integration. It can then pull the unique_id from the trace itself and store it in the right place.
|
|
||
| async def async_setup(hass, config): | ||
| """Initialize the trace integration.""" | ||
| hass.data.setdefault(DATA_TRACE, {}) |
There was a problem hiding this comment.
Don't use setdefault. We only call async_setup guaranteed once.
| hass.data.setdefault(DATA_TRACE, {}) | |
| hass.data[DATA_TRACE] = {} |
| """Shared constants for automation and script tracing and debugging.""" | ||
|
|
||
| DATA_TRACE = "trace" | ||
| STORED_TRACES = 5 # Stored traces per automation |
There was a problem hiding this comment.
| STORED_TRACES = 5 # Stored traces per automation | |
| STORED_TRACES = 5 # Stored traces per item |
| @@ -0,0 +1,35 @@ | |||
| """Support for automation and script tracing and debugging.""" | |||
There was a problem hiding this comment.
This file needs a better name. Any reason we wouldn't just put this in the __init__? We don't want other integrations to be aware of implementation details of the trace integration.
|
|
||
|
|
||
| @callback | ||
| def get_debug_traces_for_automation(hass, automation_id, summary=False): |
There was a problem hiding this comment.
Why is this _for_automation ? I would expect a generic fetch method that also tells integration to pass in their DOMAIN.
|
Comments will be addressed in a follow-up PR. |
Proposed change
Refactor tracing: Move trace support to its own integration
This is in preparation for adding support for tracing of scripts.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: