mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-22 17:03:37 +02:00
converted switches
This commit is contained in:
parent
2ea35dec75
commit
727a075dbb
3 changed files with 39 additions and 34 deletions
|
@ -5,7 +5,7 @@ PLATFORMS = [
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
# Platform.DEVICE_TRACKER,
|
# Platform.DEVICE_TRACKER,
|
||||||
# Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
# Platform.BUTTON,
|
# Platform.BUTTON,
|
||||||
# Platform.UPDATE,
|
# Platform.UPDATE,
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
"""Support for the Mikrotik Router switches."""
|
"""Support for the Mikrotik Router switches."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
from logging import getLogger
|
||||||
from typing import Any, Optional
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
|
|
||||||
|
from .entity import MikrotikEntity, async_add_entities
|
||||||
from .helper import format_attribute
|
from .helper import format_attribute
|
||||||
from .entity import model_async_setup_entry, MikrotikEntity
|
|
||||||
from .switch_types import (
|
from .switch_types import (
|
||||||
SENSOR_TYPES,
|
SENSOR_TYPES,
|
||||||
SENSOR_SERVICES,
|
SENSOR_SERVICES,
|
||||||
|
@ -15,13 +21,17 @@ from .switch_types import (
|
||||||
DEVICE_ATTRIBUTES_IFACE_WIRELESS,
|
DEVICE_ATTRIBUTES_IFACE_WIRELESS,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# async_setup_entry
|
# async_setup_entry
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
_async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Set up entry for component"""
|
"""Set up entry for component"""
|
||||||
dispatcher = {
|
dispatcher = {
|
||||||
"MikrotikSwitch": MikrotikSwitch,
|
"MikrotikSwitch": MikrotikSwitch,
|
||||||
|
@ -32,14 +42,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"MikrotikQueueSwitch": MikrotikQueueSwitch,
|
"MikrotikQueueSwitch": MikrotikQueueSwitch,
|
||||||
"MikrotikKidcontrolPauseSwitch": MikrotikKidcontrolPauseSwitch,
|
"MikrotikKidcontrolPauseSwitch": MikrotikKidcontrolPauseSwitch,
|
||||||
}
|
}
|
||||||
await model_async_setup_entry(
|
await async_add_entities(hass, config_entry, dispatcher)
|
||||||
hass,
|
|
||||||
config_entry,
|
|
||||||
async_add_entities,
|
|
||||||
SENSOR_SERVICES,
|
|
||||||
SENSOR_TYPES,
|
|
||||||
dispatcher,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
"""Definitions for Mikrotik Router switch entities."""
|
"""Definitions for Mikrotik Router switch entities."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import List
|
from typing import List
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||||
|
@ -164,25 +166,25 @@ class MikrotikSwitchEntityDescription(SwitchEntityDescription):
|
||||||
|
|
||||||
device_class: str = SwitchDeviceClass.SWITCH
|
device_class: str = SwitchDeviceClass.SWITCH
|
||||||
|
|
||||||
icon_enabled: str = ""
|
icon_enabled: str | None = None
|
||||||
icon_disabled: str = ""
|
icon_disabled: str | None = None
|
||||||
ha_group: str = ""
|
ha_group: str | None = None
|
||||||
ha_connection: str = ""
|
ha_connection: str | None = None
|
||||||
ha_connection_value: str = ""
|
ha_connection_value: str | None = None
|
||||||
data_path: str = ""
|
data_path: str | None = None
|
||||||
data_attribute: str = "enabled"
|
data_attribute: str = "enabled"
|
||||||
data_switch_path: str = ""
|
data_switch_path: str | None = None
|
||||||
data_switch_parameter: str = "disabled"
|
data_switch_parameter: str = "disabled"
|
||||||
data_name: str = ""
|
data_name: str | None = None
|
||||||
data_name_comment: bool = False
|
data_name_comment: bool = False
|
||||||
data_uid: str = ""
|
data_uid: str | None = None
|
||||||
data_reference: str = ""
|
data_reference: str | None = None
|
||||||
data_attributes_list: List = field(default_factory=lambda: [])
|
data_attributes_list: List = field(default_factory=lambda: [])
|
||||||
func: str = "MikrotikSwitch"
|
func: str = "MikrotikSwitch"
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES: tuple[MikrotikSensorEntityDescription, ...] = (
|
||||||
"interface": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="interface",
|
key="interface",
|
||||||
name="Port",
|
name="Port",
|
||||||
icon_enabled="mdi:lan-connect",
|
icon_enabled="mdi:lan-connect",
|
||||||
|
@ -199,7 +201,7 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
func="MikrotikPortSwitch",
|
func="MikrotikPortSwitch",
|
||||||
),
|
),
|
||||||
"nat": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="nat",
|
key="nat",
|
||||||
name="",
|
name="",
|
||||||
icon_enabled="mdi:network-outline",
|
icon_enabled="mdi:network-outline",
|
||||||
|
@ -217,7 +219,7 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_NAT,
|
data_attributes_list=DEVICE_ATTRIBUTES_NAT,
|
||||||
func="MikrotikNATSwitch",
|
func="MikrotikNATSwitch",
|
||||||
),
|
),
|
||||||
"mangle": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="mangle",
|
key="mangle",
|
||||||
name="",
|
name="",
|
||||||
icon_enabled="mdi:bookmark-outline",
|
icon_enabled="mdi:bookmark-outline",
|
||||||
|
@ -235,7 +237,7 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_MANGLE,
|
data_attributes_list=DEVICE_ATTRIBUTES_MANGLE,
|
||||||
func="MikrotikMangleSwitch",
|
func="MikrotikMangleSwitch",
|
||||||
),
|
),
|
||||||
"filter": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="filter",
|
key="filter",
|
||||||
name="",
|
name="",
|
||||||
icon_enabled="mdi:filter-variant",
|
icon_enabled="mdi:filter-variant",
|
||||||
|
@ -253,7 +255,7 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_FILTER,
|
data_attributes_list=DEVICE_ATTRIBUTES_FILTER,
|
||||||
func="MikrotikFilterSwitch",
|
func="MikrotikFilterSwitch",
|
||||||
),
|
),
|
||||||
"ppp_secret": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="ppp_secret",
|
key="ppp_secret",
|
||||||
name="PPP Secret",
|
name="PPP Secret",
|
||||||
icon_enabled="mdi:account-outline",
|
icon_enabled="mdi:account-outline",
|
||||||
|
@ -269,7 +271,7 @@ SENSOR_TYPES = {
|
||||||
data_reference="name",
|
data_reference="name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_PPP_SECRET,
|
data_attributes_list=DEVICE_ATTRIBUTES_PPP_SECRET,
|
||||||
),
|
),
|
||||||
"queue": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="queue",
|
key="queue",
|
||||||
name="",
|
name="",
|
||||||
icon_enabled="mdi:leaf",
|
icon_enabled="mdi:leaf",
|
||||||
|
@ -286,7 +288,7 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_QUEUE,
|
data_attributes_list=DEVICE_ATTRIBUTES_QUEUE,
|
||||||
func="MikrotikQueueSwitch",
|
func="MikrotikQueueSwitch",
|
||||||
),
|
),
|
||||||
"kidcontrol_enable": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="kidcontrol_enable",
|
key="kidcontrol_enable",
|
||||||
name="",
|
name="",
|
||||||
icon_enabled="mdi:account",
|
icon_enabled="mdi:account",
|
||||||
|
@ -302,7 +304,7 @@ SENSOR_TYPES = {
|
||||||
data_reference="name",
|
data_reference="name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
|
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
|
||||||
),
|
),
|
||||||
"kidcontrol_pause": MikrotikSwitchEntityDescription(
|
MikrotikSwitchEntityDescription(
|
||||||
key="kidcontrol_paused",
|
key="kidcontrol_paused",
|
||||||
name="paused",
|
name="paused",
|
||||||
icon_enabled="mdi:account-outline",
|
icon_enabled="mdi:account-outline",
|
||||||
|
@ -320,6 +322,6 @@ SENSOR_TYPES = {
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
|
data_attributes_list=DEVICE_ATTRIBUTES_KIDCONTROL,
|
||||||
func="MikrotikKidcontrolPauseSwitch",
|
func="MikrotikKidcontrolPauseSwitch",
|
||||||
),
|
),
|
||||||
}
|
)
|
||||||
|
|
||||||
SENSOR_SERVICES = {}
|
SENSOR_SERVICES = {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue