centralized in one point the hid

This commit is contained in:
Cayo Puigdefabregas 2020-11-12 20:57:33 +01:00
parent 554ec254d8
commit 82a3344965
1 changed files with 8 additions and 4 deletions

View File

@ -455,16 +455,20 @@ class Computer(Device):
if privacy 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, """Returns the Naming.hid with the first mac of network adapter,
following an alphabetical order. following an alphabetical order.
""" """
self.set_hid() self.set_hid()
if not self.hid: if not self.hid:
return 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() macs_network.sort()
mac = "-"+macs_network[0] if macs_network else '' mac = macs_network[0] if macs_network else ''
if not mac or mac in self.hid:
return
mac = f"-{mac}"
self.hid += mac self.hid += mac
def __format__(self, format_spec): def __format__(self, format_spec):