From ce98668f1ef7fbbf1c1e57f4fee257b1b7984f44 Mon Sep 17 00:00:00 2001 From: tomaae <23486452+tomaae@users.noreply.github.com> Date: Sat, 7 Dec 2019 20:50:00 +0100 Subject: [PATCH] formatting entity attributes --- .../mikrotik_router/device_tracker.py | 10 +++++++++- custom_components/mikrotik_router/switch.py | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/custom_components/mikrotik_router/device_tracker.py b/custom_components/mikrotik_router/device_tracker.py index 7bc7ddb..f60bc72 100644 --- a/custom_components/mikrotik_router/device_tracker.py +++ b/custom_components/mikrotik_router/device_tracker.py @@ -34,6 +34,14 @@ DEVICE_ATTRIBUTES = [ "default-name", ] +def format_attribute(attr): + res = attr.replace("-", " ") + res = res.capitalize() + res = res.replace(" ip ", " IP ") + res = res.replace(" mac ", " MAC ") + res = res.replace(" mtu", " MTU") + return res + # --------------------------- # async_setup_entry @@ -168,6 +176,6 @@ class MikrotikControllerPortDeviceTracker(ScannerEntity): for variable in DEVICE_ATTRIBUTES: if variable in self._data: - attributes[variable] = self._data[variable] + attributes[format_attribute(variable)] = self._data[variable] return attributes diff --git a/custom_components/mikrotik_router/switch.py b/custom_components/mikrotik_router/switch.py index 20b7fc3..6bb10ac 100644 --- a/custom_components/mikrotik_router/switch.py +++ b/custom_components/mikrotik_router/switch.py @@ -55,6 +55,14 @@ DEVICE_ATTRIBUTES_SCRIPT = [ "run-count", ] +def format_attribute(attr): + res = attr.replace("-", " ") + res = res.capitalize() + res = res.replace(" ip ", " IP ") + res = res.replace(" mac ", " MAC ") + res = res.replace(" mtu", " MTU") + return res + # --------------------------- # async_setup_entry @@ -200,7 +208,7 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch): for variable in DEVICE_ATTRIBUTES_IFACE: if variable in self._data: - attributes[variable] = self._data[variable] + attributes[format_attribute(variable)] = self._data[variable] return attributes @@ -290,7 +298,7 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch): for variable in DEVICE_ATTRIBUTES_NAT: if variable in self._data: - attributes[variable] = self._data[variable] + attributes[format_attribute(variable)] = self._data[variable] return attributes @@ -375,7 +383,7 @@ class MikrotikControllerScriptSwitch(MikrotikControllerSwitch): for variable in DEVICE_ATTRIBUTES_SCRIPT: if variable in self._data: - attributes[variable] = self._data[variable] + attributes[format_attribute(variable)] = self._data[variable] return attributes