Expose host in ubus device tracker (#80621)

* Expose host in ubus device tracker

* Update homeassistant/components/ubus/device_tracker.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Christopher Johnson 2023-06-28 12:27:47 +01:00 committed by GitHub
parent 796b5ef196
commit c2cd4d0517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,13 +75,13 @@ class UbusDeviceScanner(DeviceScanner):
def __init__(self, config):
"""Initialize the scanner."""
host = config[CONF_HOST]
self.host = config[CONF_HOST]
self.username = config[CONF_USERNAME]
self.password = config[CONF_PASSWORD]
self.parse_api_pattern = re.compile(r"(?P<param>\w*) = (?P<value>.*);")
self.last_results = {}
self.url = f"http://{host}/ubus"
self.url = f"http://{self.host}/ubus"
self.ubus = Ubus(self.url, self.username, self.password)
self.hostapd = []
@ -108,6 +108,10 @@ class UbusDeviceScanner(DeviceScanner):
name = self.mac2name.get(device.upper(), None)
return name
async def async_get_extra_attributes(self, device: str) -> dict[str, str]:
"""Return the host to distinguish between multiple routers."""
return {"host": self.host}
@_refresh_on_access_denied
def _update_info(self):
"""Ensure the information from the router is up to date.