From 82a3344965b4cab0f374047adbf4b289f645b500 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 12 Nov 2020 20:57:33 +0100 Subject: [PATCH] centralized in one point the hid --- ereuse_devicehub/resources/device/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 58066798..4efd0189 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -455,17 +455,21 @@ class Computer(Device): if privacy ) - def add_mac_to_hid(self) -> str: + def add_mac_to_hid(self, components_snap=None): """Returns the Naming.hid with the first mac of network adapter, following an alphabetical order. """ self.set_hid() if not self.hid: return - macs_network= [c.serial_number for c in self.components if c.type == 'NetworkAdapter'] + components = self.components if components_snap == None else components_snap + macs_network= [c.serial_number for c in components if c.type == 'NetworkAdapter'] macs_network.sort() - mac = "-"+macs_network[0] if macs_network else '' - self.hid += mac + mac = macs_network[0] if macs_network else '' + if not mac or mac in self.hid: + return + mac = f"-{mac}" + self.hid += mac def __format__(self, format_spec): if not format_spec: