* Move state length validation to StateMachine async_set method
We call validate_state to make sure we do not allow any states
into the state machine that have a length>255 so we do not break
the recorder. Since async_set_internal already requires callers
to pre-validate the state, we can move the check to async_set
instead of at State object creation time to avoid needing to
check it twice in the hot path (entity write state)
* move check in async_set_internal so it only happens on state change
* no need to check if same_state
* Reduce ref counting in _async_write_ha_state
It no longer makes sense to keep a temp reference
to entity_id and hass since the function was
refactored and there are very few accesses now.
* one more place we can reduce ref counts
* Always do thread safety check when writing state
Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.
Previously the check was limited to custom components
because they were the most common source of thread
safety issues.
* Always do thread safety check when writing state
Refactor the 3 most common places where the thread safety check
for the event loop to be inline to make the check fast enough
that we can keep it long term. While code review catches most
of the thread safety issues in core, some of them still make
it through, and new ones keep getting added. Its not possible
to catch them all with manual code review, so its worth the
tiny overhead to check each time.
Previously the check was limited to custom components
because they were the most common source of thread
safety issues.
* async_fire is more common than expected with ccs
* fix mock
* fix hass mocking
* Add thread safety checks to async_create_task
Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here
* Add thread safety checks to async_create_task
Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here
* missed one
* Update homeassistant/core.py
* fix mocks
* one more internal
* more places where internal can be used
* more places where internal can be used
* more places where internal can be used
* internal one more place since this is high volume and was already eager_start
* Make release channel a hardcoded enum rather than a free form string
* Update enum comparison to remove equality and us identity comparison
* Fix comparison condition to match the previous implementation
* Update tests to use Enum instead of string