mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 02:44:31 +02:00
Format with black
This commit is contained in:
parent
44fe6a626b
commit
5650d7f5ca
17 changed files with 48 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
||||||
"""Mikrotik Router integration."""
|
"""Mikrotik Router integration."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""API parser for JSON APIs."""
|
"""API parser for JSON APIs."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Support for the Mikrotik Router binary sensor service."""
|
"""Support for the Mikrotik Router binary sensor service."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for Mikrotik Router binary sensor entities."""
|
"""Definitions for Mikrotik Router binary sensor entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Support for the Mikrotik Router buttons."""
|
"""Support for the Mikrotik Router buttons."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for Mikrotik Router button entities."""
|
"""Definitions for Mikrotik Router button entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Constants used by the Mikrotik Router component and platforms."""
|
"""Constants used by the Mikrotik Router component and platforms."""
|
||||||
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
|
|
|
@ -186,12 +186,12 @@ class MikrotikTrackerCoordinator(DataUpdateCoordinator[None]):
|
||||||
"Ping host: %s", self.coordinator.ds["host"][uid]["address"]
|
"Ping host: %s", self.coordinator.ds["host"][uid]["address"]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.coordinator.ds["host"][uid][
|
self.coordinator.ds["host"][uid]["available"] = (
|
||||||
"available"
|
await self.hass.async_add_executor_job(
|
||||||
] = await self.hass.async_add_executor_job(
|
self.api.arp_ping,
|
||||||
self.api.arp_ping,
|
self.coordinator.ds["host"][uid]["address"],
|
||||||
self.coordinator.ds["host"][uid]["address"],
|
tmp_interface,
|
||||||
tmp_interface,
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update last seen
|
# Update last seen
|
||||||
|
@ -519,31 +519,34 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]):
|
||||||
if "wifiwave2" in packages and packages["wifiwave2"]["enabled"]:
|
if "wifiwave2" in packages and packages["wifiwave2"]["enabled"]:
|
||||||
self.support_capsman = False
|
self.support_capsman = False
|
||||||
self._wifimodule = "wifiwave2"
|
self._wifimodule = "wifiwave2"
|
||||||
|
|
||||||
elif "wifi" in packages and packages["wifi"]["enabled"]:
|
elif "wifi" in packages and packages["wifi"]["enabled"]:
|
||||||
self.support_capsman = False
|
self.support_capsman = False
|
||||||
self._wifimodule = "wifi"
|
self._wifimodule = "wifi"
|
||||||
|
|
||||||
elif "wifi-qcom" in packages and packages["wifi-qcom"]["enabled"]:
|
elif "wifi-qcom" in packages and packages["wifi-qcom"]["enabled"]:
|
||||||
self.support_capsman = False
|
self.support_capsman = False
|
||||||
self._wifimodule = "wifi"
|
self._wifimodule = "wifi"
|
||||||
|
|
||||||
elif "wifi-qcom-ac" in packages and packages["wifi-qcom-ac"]["enabled"]:
|
elif "wifi-qcom-ac" in packages and packages["wifi-qcom-ac"]["enabled"]:
|
||||||
self.support_capsman = False
|
self.support_capsman = False
|
||||||
self._wifimodule = "wifi"
|
self._wifimodule = "wifi"
|
||||||
|
|
||||||
elif (self.major_fw_version == 7 and self.minor_fw_version >= 13) or self.major_fw_version > 7:
|
elif (
|
||||||
|
self.major_fw_version == 7 and self.minor_fw_version >= 13
|
||||||
|
) or self.major_fw_version > 7:
|
||||||
self.support_capsman = False
|
self.support_capsman = False
|
||||||
self._wifimodule = "wifi"
|
self._wifimodule = "wifi"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.support_capsman = True
|
self.support_capsman = True
|
||||||
self.support_wireless = bool(self.minor_fw_version < 13)
|
self.support_wireless = bool(self.minor_fw_version < 13)
|
||||||
|
|
||||||
_LOGGER.debug("Mikrotik %s wifi module=%s",
|
_LOGGER.debug(
|
||||||
self.host,
|
"Mikrotik %s wifi module=%s",
|
||||||
self._wifimodule,
|
self.host,
|
||||||
)
|
self._wifimodule,
|
||||||
|
)
|
||||||
|
|
||||||
if "ups" in packages and packages["ups"]["enabled"]:
|
if "ups" in packages and packages["ups"]["enabled"]:
|
||||||
self.support_ups = True
|
self.support_ups = True
|
||||||
|
@ -1580,7 +1583,7 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]):
|
||||||
if self.ds["fw-update"]["installed-version"] != "unknown":
|
if self.ds["fw-update"]["installed-version"] != "unknown":
|
||||||
try:
|
try:
|
||||||
full_version = self.ds["fw-update"].get("installed-version")
|
full_version = self.ds["fw-update"].get("installed-version")
|
||||||
split_end = min(len(full_version),4)
|
split_end = min(len(full_version), 4)
|
||||||
version = re.sub(r"[^0-9\.]", "", full_version[0:split_end])
|
version = re.sub(r"[^0-9\.]", "", full_version[0:split_end])
|
||||||
self.major_fw_version = int(version.split(".")[0])
|
self.major_fw_version = int(version.split(".")[0])
|
||||||
self.minor_fw_version = int(version.split(".")[1])
|
self.minor_fw_version = int(version.split(".")[1])
|
||||||
|
@ -1589,7 +1592,7 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]):
|
||||||
self.host,
|
self.host,
|
||||||
self.major_fw_version,
|
self.major_fw_version,
|
||||||
self.minor_fw_version,
|
self.minor_fw_version,
|
||||||
full_version
|
full_version,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
@ -1987,13 +1990,15 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]):
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def get_capsman_hosts(self) -> None:
|
def get_capsman_hosts(self) -> None:
|
||||||
"""Get CAPS-MAN hosts data from Mikrotik"""
|
"""Get CAPS-MAN hosts data from Mikrotik"""
|
||||||
|
|
||||||
if self.major_fw_version > 7 or (self.major_fw_version == 7 and self.minor_fw_version >= 13):
|
if self.major_fw_version > 7 or (
|
||||||
|
self.major_fw_version == 7 and self.minor_fw_version >= 13
|
||||||
|
):
|
||||||
registration_path = "/interface/wifi/registration-table"
|
registration_path = "/interface/wifi/registration-table"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
registration_path= "/caps-man/registration-table"
|
registration_path = "/caps-man/registration-table"
|
||||||
|
|
||||||
self.ds["capsman_hosts"] = parse_api(
|
self.ds["capsman_hosts"] = parse_api(
|
||||||
data={},
|
data={},
|
||||||
source=self.api.query(registration_path),
|
source=self.api.query(registration_path),
|
||||||
|
@ -2262,9 +2267,9 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]):
|
||||||
# Resolve manufacturer
|
# Resolve manufacturer
|
||||||
if vals["manufacturer"] == "detect" and vals["mac-address"] != "unknown":
|
if vals["manufacturer"] == "detect" and vals["mac-address"] != "unknown":
|
||||||
try:
|
try:
|
||||||
self.ds["host"][uid][
|
self.ds["host"][uid]["manufacturer"] = (
|
||||||
"manufacturer"
|
await self.async_mac_lookup.lookup(vals["mac-address"])
|
||||||
] = await self.async_mac_lookup.lookup(vals["mac-address"])
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.ds["host"][uid]["manufacturer"] = ""
|
self.ds["host"][uid]["manufacturer"] = ""
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Support for the Mikrotik Router device tracker."""
|
"""Support for the Mikrotik Router device tracker."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for Mikrotik Router device tracker entities."""
|
"""Definitions for Mikrotik Router device tracker entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Diagnostics support for Mikrotik Router."""
|
"""Diagnostics support for Mikrotik Router."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from homeassistant.components.diagnostics import async_redact_data
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Mikrotik HA shared entity model"""
|
"""Mikrotik HA shared entity model"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Mikrotik sensor platform."""
|
"""Mikrotik sensor platform."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for sensor entities."""
|
"""Definitions for sensor entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Support for the Mikrotik Router switches."""
|
"""Support for the Mikrotik Router switches."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for Mikrotik Router switch entities."""
|
"""Definitions for Mikrotik Router switch entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Definitions for Mikrotik Router update entities."""
|
"""Definitions for Mikrotik Router update entities."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue