mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-28 11:40:08 +02:00
renamed format_attribute to helper.py
This commit is contained in:
parent
1ea1f3a4b7
commit
a3e6761c78
6 changed files with 27 additions and 95 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
|
@ -17,7 +16,7 @@ from homeassistant.const import (
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
|
from .helper import format_attribute
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DATA_CLIENT,
|
DATA_CLIENT,
|
||||||
|
@ -116,22 +115,6 @@ DEVICE_ATTRIBUTES_PPP_SECRET = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# format_attribute
|
|
||||||
# ---------------------------
|
|
||||||
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")
|
|
||||||
res = res.replace("Sfp", "SFP")
|
|
||||||
res = res.replace("Poe", "POE")
|
|
||||||
res = res.replace(" tx", " TX")
|
|
||||||
res = res.replace(" rx", " RX")
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# format_value
|
# format_value
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -2,13 +2,12 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity
|
from homeassistant.components.button import ButtonEntity
|
||||||
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
|
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
from .helper import format_attribute
|
||||||
from .const import DOMAIN, DATA_CLIENT, ATTRIBUTION
|
from .const import DOMAIN, DATA_CLIENT, ATTRIBUTION
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -19,22 +18,6 @@ DEVICE_ATTRIBUTES_SCRIPT = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# format_attribute
|
|
||||||
# ---------------------------
|
|
||||||
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")
|
|
||||||
res = res.replace("Sfp", "SFP")
|
|
||||||
res = res.replace("Poe", "POE")
|
|
||||||
res = res.replace(" tx", " TX")
|
|
||||||
res = res.replace(" rx", " RX")
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -15,7 +15,7 @@ from homeassistant.core import callback
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.util.dt import get_age, utcnow
|
from homeassistant.util.dt import get_age, utcnow
|
||||||
|
from .helper import format_attribute
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
DATA_CLIENT,
|
DATA_CLIENT,
|
||||||
|
@ -38,22 +38,6 @@ DEVICE_ATTRIBUTES_HOST = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# format_attribute
|
|
||||||
# ---------------------------
|
|
||||||
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")
|
|
||||||
res = res.replace("Sfp", "SFP")
|
|
||||||
res = res.replace("Poe", "POE")
|
|
||||||
res = res.replace(" tx", " TX")
|
|
||||||
res = res.replace(" rx", " RX")
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# format_value
|
# format_value
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
17
custom_components/mikrotik_router/helper.py
Normal file
17
custom_components/mikrotik_router/helper.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
"""Helper functions for Mikrotik Router."""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# format_attribute
|
||||||
|
# ---------------------------
|
||||||
|
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")
|
||||||
|
res = res.replace("Sfp", "SFP")
|
||||||
|
res = res.replace("Poe", "POE")
|
||||||
|
res = res.replace(" tx", " TX")
|
||||||
|
res = res.replace(" rx", " RX")
|
||||||
|
return res
|
|
@ -1,28 +1,25 @@
|
||||||
"""Implementation of Mikrotik Router sensor entities."""
|
"""Implementation of Mikrotik Router sensor entities."""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from .helper import format_attribute
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_SENSOR_PORT_TRAFFIC,
|
CONF_SENSOR_PORT_TRAFFIC,
|
||||||
DEFAULT_SENSOR_PORT_TRAFFIC,
|
DEFAULT_SENSOR_PORT_TRAFFIC,
|
||||||
|
DOMAIN,
|
||||||
|
DATA_CLIENT,
|
||||||
|
ATTRIBUTION,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
|
|
||||||
from .const import DOMAIN, DATA_CLIENT, ATTRIBUTION
|
|
||||||
from .sensor_types import (
|
from .sensor_types import (
|
||||||
MikrotikSensorEntityDescription,
|
MikrotikSensorEntityDescription,
|
||||||
SENSOR_TYPES,
|
SENSOR_TYPES,
|
||||||
|
@ -31,22 +28,6 @@ from .sensor_types import (
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# format_attribute
|
|
||||||
# ---------------------------
|
|
||||||
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")
|
|
||||||
res = res.replace("Sfp", "SFP")
|
|
||||||
res = res.replace("Poe", "POE")
|
|
||||||
res = res.replace(" tx", " TX")
|
|
||||||
res = res.replace(" rx", " RX")
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.core import callback
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
from .helper import format_attribute
|
||||||
from .const import DOMAIN, DATA_CLIENT, ATTRIBUTION
|
from .const import DOMAIN, DATA_CLIENT, ATTRIBUTION
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -151,22 +151,6 @@ DEVICE_ATTRIBUTES_QUEUE = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
|
||||||
# format_attribute
|
|
||||||
# ---------------------------
|
|
||||||
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")
|
|
||||||
res = res.replace("Sfp", "SFP")
|
|
||||||
res = res.replace("Poe", "POE")
|
|
||||||
res = res.replace(" tx", " TX")
|
|
||||||
res = res.replace(" rx", " RX")
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue