mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-27 11:18:55 +02:00
Modified variable hostname to host-name to keep inline with Mikrotik API
This commit is contained in:
parent
1bb90d51cd
commit
023f45cf26
2 changed files with 13 additions and 13 deletions
|
@ -38,7 +38,7 @@ DEVICE_ATTRIBUTES_IFACE = [
|
||||||
]
|
]
|
||||||
|
|
||||||
DEVICE_ATTRIBUTES_HOST = [
|
DEVICE_ATTRIBUTES_HOST = [
|
||||||
"hostname",
|
"host-name",
|
||||||
"address",
|
"address",
|
||||||
"mac-address",
|
"mac-address",
|
||||||
"interface",
|
"interface",
|
||||||
|
@ -234,7 +234,7 @@ class MikrotikControllerHostDeviceTracker(ScannerEntity):
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"New host tracker %s (%s - %s)",
|
"New host tracker %s (%s - %s)",
|
||||||
self._inst,
|
self._inst,
|
||||||
self._data["hostname"],
|
self._data["host-name"],
|
||||||
self._data["mac-address"],
|
self._data["mac-address"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ class MikrotikControllerHostDeviceTracker(ScannerEntity):
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the host."""
|
"""Return the name of the host."""
|
||||||
return f"{self._data['hostname']}"
|
return f"{self._data['host-name']}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
|
|
@ -797,30 +797,30 @@ class MikrotikControllerData:
|
||||||
for uid, vals in self.data["host"].items():
|
for uid, vals in self.data["host"].items():
|
||||||
# Add missing default values
|
# Add missing default values
|
||||||
for key, default in zip(
|
for key, default in zip(
|
||||||
["address", "mac-address", "interface", "hostname", "last-seen", "available"],
|
["address", "mac-address", "interface", "host-name", "last-seen", "available"],
|
||||||
["unknown", "unknown", "unknown", "unknown", False],
|
["unknown", "unknown", "unknown", "unknown", False],
|
||||||
):
|
):
|
||||||
if key not in self.data["host"][uid]:
|
if key not in self.data["host"][uid]:
|
||||||
self.data["host"][uid][key] = default
|
self.data["host"][uid][key] = default
|
||||||
|
|
||||||
# Resolve hostname
|
# Resolve hostname
|
||||||
if vals["hostname"] == "unknown":
|
if vals["host-name"] == "unknown":
|
||||||
if vals["address"] != "unknown":
|
if vals["address"] != "unknown":
|
||||||
for dns_uid, dns_vals in self.data["dns"].items():
|
for dns_uid, dns_vals in self.data["dns"].items():
|
||||||
if dns_vals["address"] == vals["address"]:
|
if dns_vals["address"] == vals["address"]:
|
||||||
self.data["host"][uid]["hostname"] = dns_vals["name"].split('.')[0]
|
self.data["host"][uid]["host-name"] = dns_vals["name"].split('.')[0]
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.data["host"][uid]["hostname"] == "unknown" \
|
if self.data["host"][uid]["host-name"] == "unknown" \
|
||||||
and uid in self.data["dhcp"] and self.data["dhcp"][uid]["comment"] != "":
|
and uid in self.data["dhcp"] and self.data["dhcp"][uid]["comment"] != "":
|
||||||
self.data["host"][uid]["hostname"] = self.data["dhcp"][uid]["comment"]
|
self.data["host"][uid]["host-name"] = self.data["dhcp"][uid]["comment"]
|
||||||
|
|
||||||
elif self.data["host"][uid]["hostname"] == "unknown" \
|
elif self.data["host"][uid]["host-name"] == "unknown" \
|
||||||
and uid in self.data["dhcp"] and self.data["dhcp"][uid]["host-name"] != "unknown":
|
and uid in self.data["dhcp"] and self.data["dhcp"][uid]["host-name"] != "unknown":
|
||||||
self.data["host"][uid]["hostname"] = self.data["dhcp"][uid]["host-name"]
|
self.data["host"][uid]["host-name"] = self.data["dhcp"][uid]["host-name"]
|
||||||
|
|
||||||
elif self.data["host"][uid]["hostname"] == "unknown":
|
elif self.data["host"][uid]["host-name"] == "unknown":
|
||||||
self.data["host"][uid]["hostname"] = uid
|
self.data["host"][uid]["host-name"] = uid
|
||||||
|
|
||||||
# Check host availability
|
# Check host availability
|
||||||
if vals["address"] != "unknown" and vals["interface"] != "unknown":
|
if vals["address"] != "unknown" and vals["interface"] != "unknown":
|
||||||
|
@ -856,7 +856,7 @@ class MikrotikControllerData:
|
||||||
self.data["accounting"][uid] = {
|
self.data["accounting"][uid] = {
|
||||||
'address': vals['address'],
|
'address': vals['address'],
|
||||||
'mac-address': vals['mac-address'],
|
'mac-address': vals['mac-address'],
|
||||||
'host-name': vals['hostname'],
|
'host-name': vals['host-name'],
|
||||||
'tx-rx-attr': traffic_type,
|
'tx-rx-attr': traffic_type,
|
||||||
'available': False,
|
'available': False,
|
||||||
'local_accounting': False
|
'local_accounting': False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue