What happened?
It looks like Entity.is_on() and Entity.is_state() don't work correctly in async callbacks.
def initialize():
self._entity = self.get_entity("...")
self._entity.listen_state(self._state_changed)
async def _state_changed(self, entity: str, attribute: str, old: Any, new: Any, **kwargs: Any) -> None:
self.log(f"State: {self._entity.state}; is_state: {self._entity.is_state('on')}; is_on: {self._entity.is_on()}")
Outputs:
State: on; is_state: False; is_on: False
I suspect this is because is_state calls entity_state = self.get_state(copy=False). get_state returns a Coroutine in async contexts, but this isn't awaited by is_state.
Version
b8b06ba
Installation type
Python virtual environment
Relevant log output
Relevant code in the app or config file that caused the issue
Anything else?
No response
What happened?
It looks like
Entity.is_on()andEntity.is_state()don't work correctly in async callbacks.Outputs:
I suspect this is because
is_statecallsentity_state = self.get_state(copy=False).get_statereturns a Coroutine in async contexts, but this isn't awaited byis_state.Version
b8b06ba
Installation type
Python virtual environment
Relevant log output
Relevant code in the app or config file that caused the issue
Anything else?
No response