1 """Support for scanning a network with nmap."""
3 from __future__
import annotations
14 from .
import NmapDevice, NmapDeviceScanner, short_hostname, signal_device_update
15 from .const
import DOMAIN
17 _LOGGER = logging.getLogger(__name__)
21 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
23 """Set up device tracker for Nmap Tracker component."""
24 nmap_tracker = hass.data[DOMAIN][entry.entry_id]
27 def device_new(mac_address):
28 """Signal a new device."""
32 def device_missing(mac_address):
33 """Signal a missing device."""
36 entry.async_on_unload(
39 entry.async_on_unload(
41 hass, nmap_tracker.signal_device_missing, device_missing
47 """An Nmap Tracker entity."""
49 _attr_should_poll =
False
50 _attr_translation_key =
"device_tracker"
53 self, nmap_tracker: NmapDeviceScanner, mac_address: str, active: bool
55 """Initialize an nmap tracker entity."""
63 """Get latest device state."""
68 """Return device status."""
73 """Return device name."""
78 """Return device unique id."""
83 """Return the primary ip address of the device."""
88 """Return the mac address of the device."""
93 """Return hostname of the device."""
94 if not self.
_device_device.hostname:
105 """Return the attributes."""
107 "last_time_reachable": self.
_device_device.last_update.isoformat(
110 "reason": self.
_device_device.reason,
117 self.async_write_ha_state()
120 """Register state update callback."""
121 self.async_on_remove(
None async_on_demand_update(self, bool online)
None __init__(self, NmapDeviceScanner nmap_tracker, str mac_address, bool active)
None async_added_to_hass(self)
dict[str, Any] extra_state_attributes(self)
None async_process_update(self, bool online)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
str signal_device_update(mac_address)
str short_hostname(str hostname)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)