Simplify mac address handling (#162)

This commit is contained in:
Teemu R 2021-05-12 15:07:53 +02:00 committed by GitHub
parent 28a902c485
commit c7a47ea1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -411,17 +411,17 @@ class SmartDevice:
"""
sys_info = self.sys_info
if "mac" in sys_info:
return str(sys_info["mac"])
elif "mic_mac" in sys_info:
return ":".join(
format(s, "02x") for s in bytes.fromhex(sys_info["mic_mac"])
)
mac = sys_info.get("mac", sys_info.get("mic_mac"))
if not mac:
raise SmartDeviceException(
"Unknown mac, please submit a bug report with sys_info output."
)
if ":" not in mac:
mac = ":".join(format(s, "02x") for s in bytes.fromhex(mac))
return mac
async def set_mac(self, mac):
"""Set the mac address.