Skip to content

Commit

Permalink
add get_uuid function, resolve #11
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics committed Apr 16, 2022
1 parent f6fe4ed commit 09b6ae6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions be_helpers/generic_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import random
import time
import ubinascii

# custom packages
# typing not natively supported on MicroPython
Expand Down Expand Up @@ -86,6 +87,27 @@ def get_random_value(lower: int = 0, upper: int = 255) -> int:
"""
return random.randint(lower, upper)

@staticmethod
def get_uuid(length: Optional[int] = None) -> bytes:
"""
Get the UUID of the device.
:param length: The length of the UUID
:type length: int, optional
:returns: The uuid.
:rtype: bytes
"""
uuid = ubinascii.hexlify(machine.unique_id())

if length:
uuid_len = len(uuid)
amount = length // uuid_len + (length % uuid_len > 0)

return (uuid * amount)[:length]
else:
return uuid

@staticmethod
def df(path: str = '//', unit: Optional[str] = None) -> Union[int, str]:
"""
Expand Down

0 comments on commit 09b6ae6

Please sign in to comment.