diff --git a/custom_components/mikrotik_router/coordinator.py b/custom_components/mikrotik_router/coordinator.py index f555d34..aa4eab5 100644 --- a/custom_components/mikrotik_router/coordinator.py +++ b/custom_components/mikrotik_router/coordinator.py @@ -2090,10 +2090,9 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]): self.ds["host"][uid]["bypassed"] = self.ds["hostspot_host"][uid][ "bypassed" ] - else: - if "authorized" in self.ds["host"][uid]: - del self.ds["host"][uid]["authorized"] - del self.ds["host"][uid]["bypassed"] + elif "authorized" in self.ds["host"][uid]: + del self.ds["host"][uid]["authorized"] + del self.ds["host"][uid]["bypassed"] # CAPS-MAN availability if vals["source"] == "capsman" and uid not in capsman_detected: @@ -2152,29 +2151,28 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]): ].split(".")[0] break - # Resolve hostname from DHCP comment - if ( - self.ds["host"][uid]["host-name"] == "unknown" - and uid in self.ds["dhcp"] - and self.ds["dhcp"][uid]["enabled"] - and self.ds["dhcp"][uid]["comment"].split("#", 1)[0] != "" - ): - self.ds["host"][uid]["host-name"] = self.ds["dhcp"][uid][ - "comment" - ].split("#", 1)[0] - # Resolve hostname from DHCP hostname - elif ( - self.ds["host"][uid]["host-name"] == "unknown" - and uid in self.ds["dhcp"] - and self.ds["dhcp"][uid]["enabled"] - and self.ds["dhcp"][uid]["host-name"] != "unknown" - ): - self.ds["host"][uid]["host-name"] = self.ds["dhcp"][uid][ - "host-name" - ] - # Fallback to mac address for hostname - elif self.ds["host"][uid]["host-name"] == "unknown": - self.ds["host"][uid]["host-name"] = uid + if self.ds["host"][uid]["host-name"] == "unknown": + # Resolve hostname from DHCP comment + if ( + uid in self.ds["dhcp"] + and self.ds["dhcp"][uid]["enabled"] + and self.ds["dhcp"][uid]["comment"].split("#", 1)[0] != "" + ): + self.ds["host"][uid]["host-name"] = self.ds["dhcp"][uid][ + "comment" + ].split("#", 1)[0] + # Resolve hostname from DHCP hostname + elif ( + uid in self.ds["dhcp"] + and self.ds["dhcp"][uid]["enabled"] + and self.ds["dhcp"][uid]["host-name"] != "unknown" + ): + self.ds["host"][uid]["host-name"] = self.ds["dhcp"][uid][ + "host-name" + ] + # Fallback to mac address for hostname + else: + self.ds["host"][uid]["host-name"] = uid # Resolve manufacturer if vals["manufacturer"] == "detect" and vals["mac-address"] != "unknown": diff --git a/custom_components/mikrotik_router/entity.py b/custom_components/mikrotik_router/entity.py index 51da66f..208a4f1 100644 --- a/custom_components/mikrotik_router/entity.py +++ b/custom_components/mikrotik_router/entity.py @@ -245,7 +245,7 @@ class MikrotikEntity(CoordinatorEntity[_MikrotikCoordinatorT], Entity): dev_connection_value = self._data[dev_connection_value] if self.entity_description.ha_group == "System": - info = DeviceInfo( + return DeviceInfo( connections={(dev_connection, f"{dev_connection_value}")}, identifiers={(dev_connection, f"{dev_connection_value}")}, name=f"{self._inst} {dev_group}", @@ -265,7 +265,7 @@ class MikrotikEntity(CoordinatorEntity[_MikrotikCoordinatorT], Entity): "manufacturer" ] - info = DeviceInfo( + return DeviceInfo( connections={(dev_connection, f"{dev_connection_value}")}, default_name=f"{dev_group}", default_manufacturer=f"{dev_manufacturer}", @@ -275,7 +275,7 @@ class MikrotikEntity(CoordinatorEntity[_MikrotikCoordinatorT], Entity): ), ) else: - info = DeviceInfo( + return DeviceInfo( connections={(dev_connection, f"{dev_connection_value}")}, default_name=f"{self._inst} {dev_group}", default_model=f"{self.coordinator.data['resource']['board-name']}", @@ -286,8 +286,6 @@ class MikrotikEntity(CoordinatorEntity[_MikrotikCoordinatorT], Entity): ), ) - return info - @property def extra_state_attributes(self) -> Mapping[str, Any]: """Return the state attributes."""