Only entity verify state writable once after success unless hass is missing (#118896)
This commit is contained in:
parent
ffea72f866
commit
62b1bde0e8
2 changed files with 15 additions and 7 deletions
|
@ -473,6 +473,10 @@ class Entity(
|
||||||
# Protect for multiple updates
|
# Protect for multiple updates
|
||||||
_update_staged = False
|
_update_staged = False
|
||||||
|
|
||||||
|
# _verified_state_writable is set to True if the entity has been verified
|
||||||
|
# to be writable. This is used to avoid repeated checks.
|
||||||
|
_verified_state_writable = False
|
||||||
|
|
||||||
# Process updates in parallel
|
# Process updates in parallel
|
||||||
parallel_updates: asyncio.Semaphore | None = None
|
parallel_updates: asyncio.Semaphore | None = None
|
||||||
|
|
||||||
|
@ -986,16 +990,20 @@ class Entity(
|
||||||
f"No entity id specified for entity {self.name}"
|
f"No entity id specified for entity {self.name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._verified_state_writable = True
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_write_ha_state_from_call_soon_threadsafe(self) -> None:
|
def _async_write_ha_state_from_call_soon_threadsafe(self) -> None:
|
||||||
"""Write the state to the state machine from the event loop thread."""
|
"""Write the state to the state machine from the event loop thread."""
|
||||||
self._async_verify_state_writable()
|
if not self.hass or not self._verified_state_writable:
|
||||||
|
self._async_verify_state_writable()
|
||||||
self._async_write_ha_state()
|
self._async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_write_ha_state(self) -> None:
|
def async_write_ha_state(self) -> None:
|
||||||
"""Write the state to the state machine."""
|
"""Write the state to the state machine."""
|
||||||
self._async_verify_state_writable()
|
if not self.hass or not self._verified_state_writable:
|
||||||
|
self._async_verify_state_writable()
|
||||||
if self.hass.loop_thread_id != threading.get_ident():
|
if self.hass.loop_thread_id != threading.get_ident():
|
||||||
report_non_thread_safe_operation("async_write_ha_state")
|
report_non_thread_safe_operation("async_write_ha_state")
|
||||||
self._async_write_ha_state()
|
self._async_write_ha_state()
|
||||||
|
|
|
@ -1662,11 +1662,6 @@ async def test_warn_no_platform(
|
||||||
ent.entity_id = "hello.world"
|
ent.entity_id = "hello.world"
|
||||||
error_message = "does not have a platform"
|
error_message = "does not have a platform"
|
||||||
|
|
||||||
# No warning if the entity has a platform
|
|
||||||
caplog.clear()
|
|
||||||
ent.async_write_ha_state()
|
|
||||||
assert error_message not in caplog.text
|
|
||||||
|
|
||||||
# Without a platform, it should trigger the warning
|
# Without a platform, it should trigger the warning
|
||||||
ent.platform = None
|
ent.platform = None
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
@ -1678,6 +1673,11 @@ async def test_warn_no_platform(
|
||||||
ent.async_write_ha_state()
|
ent.async_write_ha_state()
|
||||||
assert error_message not in caplog.text
|
assert error_message not in caplog.text
|
||||||
|
|
||||||
|
# No warning if the entity has a platform
|
||||||
|
caplog.clear()
|
||||||
|
ent.async_write_ha_state()
|
||||||
|
assert error_message not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
async def test_invalid_state(
|
async def test_invalid_state(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue