Make the device_tracker more forgiving when passed an empty ip address string (#91101)
This has come up over and over and over again fixes #87165 fixes #51980pull/91079/head^2
parent
69f751703b
commit
5f0d983df1
|
@ -348,7 +348,7 @@ class ScannerEntity(BaseTrackerEntity):
|
|||
self.mac_address,
|
||||
self.unique_id,
|
||||
)
|
||||
if self.is_connected:
|
||||
if self.is_connected and self.ip_address:
|
||||
_async_connected_device_registered(
|
||||
hass,
|
||||
self.mac_address,
|
||||
|
@ -405,7 +405,7 @@ class ScannerEntity(BaseTrackerEntity):
|
|||
"""Return the device state attributes."""
|
||||
attr: dict[str, StateType] = {}
|
||||
attr.update(super().state_attributes)
|
||||
if self.ip_address is not None:
|
||||
if self.ip_address:
|
||||
attr[ATTR_IP] = self.ip_address
|
||||
if self.mac_address is not None:
|
||||
attr[ATTR_MAC] = self.mac_address
|
||||
|
|
|
@ -195,21 +195,6 @@ async def test_connected_device_registered(
|
|||
class MockDisconnectedScannerEntity(MockScannerEntity):
|
||||
"""Mock a disconnected scanner entity."""
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
return "aa:bb:cc:dd:ee:ff"
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
return True
|
||||
|
||||
@property
|
||||
def hostname(self) -> str:
|
||||
return "connected"
|
||||
|
||||
class MockConnectedScannerEntity(MockScannerEntity):
|
||||
"""Mock a disconnected scanner entity."""
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
return "aa:bb:cc:dd:ee:00"
|
||||
|
@ -222,10 +207,44 @@ async def test_connected_device_registered(
|
|||
def hostname(self) -> str:
|
||||
return "disconnected"
|
||||
|
||||
class MockConnectedScannerEntity(MockScannerEntity):
|
||||
"""Mock a disconnected scanner entity."""
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
return "aa:bb:cc:dd:ee:ff"
|
||||
|
||||
@property
|
||||
def is_connected(self) -> bool:
|
||||
return True
|
||||
|
||||
@property
|
||||
def hostname(self) -> str:
|
||||
return "connected"
|
||||
|
||||
class MockConnectedScannerEntityBadIPAddress(MockConnectedScannerEntity):
|
||||
"""Mock a disconnected scanner entity."""
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
return "aa:bb:cc:dd:ee:01"
|
||||
|
||||
@property
|
||||
def ip_address(self) -> str:
|
||||
return ""
|
||||
|
||||
@property
|
||||
def hostname(self) -> str:
|
||||
return "connected_bad_ip"
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Mock setup entry method."""
|
||||
async_add_entities(
|
||||
[MockConnectedScannerEntity(), MockDisconnectedScannerEntity()]
|
||||
[
|
||||
MockConnectedScannerEntity(),
|
||||
MockDisconnectedScannerEntity(),
|
||||
MockConnectedScannerEntityBadIPAddress(),
|
||||
]
|
||||
)
|
||||
return True
|
||||
|
||||
|
@ -240,7 +259,7 @@ async def test_connected_device_registered(
|
|||
full_name = f"{entity_platform.domain}.{config_entry.domain}"
|
||||
assert full_name in hass.config.components
|
||||
assert len(hass.states.async_entity_ids()) == 0 # should be disabled
|
||||
assert len(entity_registry.entities) == 2
|
||||
assert len(entity_registry.entities) == 3
|
||||
assert (
|
||||
entity_registry.entities["test_domain.test_aa_bb_cc_dd_ee_ff"].config_entry_id
|
||||
== "super-mock-id"
|
||||
|
|
Loading…
Reference in New Issue