mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-01 21:14:32 +02:00
formatting entity attributes
This commit is contained in:
parent
3d90f7c19a
commit
ce98668f1e
2 changed files with 20 additions and 4 deletions
|
@ -34,6 +34,14 @@ DEVICE_ATTRIBUTES = [
|
||||||
"default-name",
|
"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
|
# async_setup_entry
|
||||||
|
@ -168,6 +176,6 @@ class MikrotikControllerPortDeviceTracker(ScannerEntity):
|
||||||
|
|
||||||
for variable in DEVICE_ATTRIBUTES:
|
for variable in DEVICE_ATTRIBUTES:
|
||||||
if variable in self._data:
|
if variable in self._data:
|
||||||
attributes[variable] = self._data[variable]
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
|
@ -55,6 +55,14 @@ DEVICE_ATTRIBUTES_SCRIPT = [
|
||||||
"run-count",
|
"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
|
# async_setup_entry
|
||||||
|
@ -200,7 +208,7 @@ class MikrotikControllerPortSwitch(MikrotikControllerSwitch):
|
||||||
|
|
||||||
for variable in DEVICE_ATTRIBUTES_IFACE:
|
for variable in DEVICE_ATTRIBUTES_IFACE:
|
||||||
if variable in self._data:
|
if variable in self._data:
|
||||||
attributes[variable] = self._data[variable]
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
@ -290,7 +298,7 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
||||||
|
|
||||||
for variable in DEVICE_ATTRIBUTES_NAT:
|
for variable in DEVICE_ATTRIBUTES_NAT:
|
||||||
if variable in self._data:
|
if variable in self._data:
|
||||||
attributes[variable] = self._data[variable]
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
@ -375,7 +383,7 @@ class MikrotikControllerScriptSwitch(MikrotikControllerSwitch):
|
||||||
|
|
||||||
for variable in DEVICE_ATTRIBUTES_SCRIPT:
|
for variable in DEVICE_ATTRIBUTES_SCRIPT:
|
||||||
if variable in self._data:
|
if variable in self._data:
|
||||||
attributes[variable] = self._data[variable]
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue