From eb381100d87f47e1f60715862f1ea70c1ec48061 Mon Sep 17 00:00:00 2001 From: David Rapan Date: Sat, 14 Dec 2024 00:08:55 +0100 Subject: [PATCH] refactor: build_device_info to use DeviceInfo class --- custom_components/solarman/common.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/custom_components/solarman/common.py b/custom_components/solarman/common.py index d5d4886..6307a13 100644 --- a/custom_components/solarman/common.py +++ b/custom_components/solarman/common.py @@ -95,6 +95,7 @@ def process_profile(filename): return filename if not filename in PROFILE_REDIRECT else PROFILE_REDIRECT[filename] def build_device_info(serial, mac, name, info, filename): + device_info = DeviceInfo() manufacturer = "Solarman" model = "Stick Logger" @@ -106,13 +107,14 @@ def build_device_info(serial, mac, name, info, filename): manufacturer = dev_man[0].capitalize() model = dev_man[1].upper() - return ({ "connections": {(CONNECTION_NETWORK_MAC, format_mac(mac))} } if mac else {}) | { - "identifiers": {(DOMAIN, serial)}, - "serial_number": serial, - "manufacturer": manufacturer, - "model": model, - "name": name - } + device_info["connections"] = {(CONNECTION_NETWORK_MAC, format_mac(mac))} if mac else {} + device_info["identifiers"] = {(DOMAIN, serial)} + device_info["serial_number"] = serial + device_info["manufacturer"] = manufacturer + device_info["model"] = model + device_info["name"] = name + + return device_info def is_platform(description, value): return (description["platform"] if "platform" in description else "sensor") == value