Do not override state property in MockEntity (#114231)

Do not override state in `MockEntity`
This commit is contained in:
Jan-Philipp Benecke 2024-03-27 11:36:00 +01:00 committed by GitHub
parent 44eeb2eb5e
commit 5c97049f2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View File

@ -83,7 +83,7 @@ from homeassistant.helpers.dispatcher import (
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.json import JSONEncoder, _orjson_default_encoder, json_dumps from homeassistant.helpers.json import JSONEncoder, _orjson_default_encoder, json_dumps
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
from homeassistant.util.async_ import run_callback_threadsafe from homeassistant.util.async_ import run_callback_threadsafe
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -1291,11 +1291,6 @@ class MockEntity(entity.Entity):
"""Return the ste of the polling.""" """Return the ste of the polling."""
return self._handle("should_poll") return self._handle("should_poll")
@property
def state(self) -> StateType:
"""Return the state of the entity."""
return self._handle("state")
@property @property
def supported_features(self) -> int | None: def supported_features(self) -> int | None:
"""Info about supported features.""" """Info about supported features."""

View File

@ -1432,9 +1432,9 @@ async def test_override_restored_entities(
component = EntityComponent(_LOGGER, DOMAIN, hass) component = EntityComponent(_LOGGER, DOMAIN, hass)
await component.async_setup({}) await component.async_setup({})
await component.async_add_entities( ent = MockEntity(unique_id="1234", entity_id="test_domain.world")
[MockEntity(unique_id="1234", state="on", entity_id="test_domain.world")], True ent._attr_state = "on"
) await component.async_add_entities([ent], True)
state = hass.states.get("test_domain.world") state = hass.states.get("test_domain.world")
assert state.state == "on" assert state.state == "on"