Complete device tracker entity tests (#108768)
parent
30c9a70dbf
commit
852e4c21c6
|
@ -132,6 +132,7 @@ def _async_register_mac(
|
|||
device_entry = dev_reg.async_get(ev.data["device_id"])
|
||||
|
||||
if device_entry is None:
|
||||
# This should not happen, since the device was just created.
|
||||
return
|
||||
|
||||
# Check if device has a mac
|
||||
|
@ -153,8 +154,7 @@ def _async_register_mac(
|
|||
if (entity_id := ent_reg.async_get_entity_id(DOMAIN, *unique_id)) is None:
|
||||
return
|
||||
|
||||
if (entity_entry := ent_reg.async_get(entity_id)) is None:
|
||||
return
|
||||
entity_entry = ent_reg.entities[entity_id]
|
||||
|
||||
# Make sure entity has a config entry and was disabled by the
|
||||
# default disable logic in the integration and new entities
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,85 +0,0 @@
|
|||
"""Tests for device tracker entities."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.device_tracker.config_entry import (
|
||||
BaseTrackerEntity,
|
||||
ScannerEntity,
|
||||
)
|
||||
from homeassistant.components.device_tracker.const import (
|
||||
ATTR_HOST_NAME,
|
||||
ATTR_IP,
|
||||
ATTR_MAC,
|
||||
ATTR_SOURCE_TYPE,
|
||||
DOMAIN,
|
||||
SourceType,
|
||||
)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_HOME, STATE_NOT_HOME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_scanner_entity_device_tracker(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
enable_custom_integrations: None,
|
||||
) -> None:
|
||||
"""Test ScannerEntity based device tracker."""
|
||||
# Make device tied to other integration so device tracker entities get enabled
|
||||
other_config_entry = MockConfigEntry(domain="not_fake_integration")
|
||||
other_config_entry.add_to_hass(hass)
|
||||
device_registry.async_get_or_create(
|
||||
name="Device from other integration",
|
||||
config_entry_id=other_config_entry.entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "ad:de:ef:be:ed:fe")},
|
||||
)
|
||||
|
||||
config_entry = MockConfigEntry(domain="test")
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_id = "device_tracker.test_ad_de_ef_be_ed_fe"
|
||||
entity_state = hass.states.get(entity_id)
|
||||
assert entity_state.attributes == {
|
||||
ATTR_SOURCE_TYPE: SourceType.ROUTER,
|
||||
ATTR_BATTERY_LEVEL: 100,
|
||||
ATTR_IP: "0.0.0.0",
|
||||
ATTR_MAC: "ad:de:ef:be:ed:fe",
|
||||
ATTR_HOST_NAME: "test.hostname.org",
|
||||
}
|
||||
assert entity_state.state == STATE_NOT_HOME
|
||||
|
||||
entity = hass.data[DOMAIN].get_entity(entity_id)
|
||||
entity.set_connected()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entity_state = hass.states.get(entity_id)
|
||||
assert entity_state.state == STATE_HOME
|
||||
|
||||
|
||||
def test_scanner_entity() -> None:
|
||||
"""Test coverage for base ScannerEntity entity class."""
|
||||
entity = ScannerEntity()
|
||||
with pytest.raises(NotImplementedError):
|
||||
assert entity.source_type is None
|
||||
with pytest.raises(NotImplementedError):
|
||||
assert entity.is_connected is None
|
||||
with pytest.raises(NotImplementedError):
|
||||
assert entity.state == STATE_NOT_HOME
|
||||
assert entity.battery_level is None
|
||||
assert entity.ip_address is None
|
||||
assert entity.mac_address is None
|
||||
assert entity.hostname is None
|
||||
|
||||
|
||||
def test_base_tracker_entity() -> None:
|
||||
"""Test coverage for base BaseTrackerEntity entity class."""
|
||||
entity = BaseTrackerEntity()
|
||||
with pytest.raises(NotImplementedError):
|
||||
assert entity.source_type is None
|
||||
assert entity.battery_level is None
|
||||
with pytest.raises(NotImplementedError):
|
||||
assert entity.state_attributes is None
|
Loading…
Reference in New Issue