mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-23 17:28:51 +02:00
Migrated to new entity naming style
This commit is contained in:
parent
1a0861fd9c
commit
0b4a7a3c72
8 changed files with 37 additions and 37 deletions
|
@ -137,7 +137,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"interface": MikrotikBinarySensorEntityDescription(
|
"interface": MikrotikBinarySensorEntityDescription(
|
||||||
key="interface",
|
key="interface",
|
||||||
name="",
|
name="Connection",
|
||||||
icon_enabled="mdi:lan-connect",
|
icon_enabled="mdi:lan-connect",
|
||||||
icon_disabled="mdi:lan-pending",
|
icon_disabled="mdi:lan-pending",
|
||||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
|
@ -146,7 +146,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_attribute="running",
|
data_attribute="running",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="default-name",
|
data_uid="default-name",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
|
|
@ -99,7 +99,7 @@ class MikrotikHostDeviceTracker(MikrotikDeviceTracker):
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return f"{self._data[self.entity_description.data_name]}"
|
return ""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
|
|
|
@ -168,6 +168,8 @@ def model_update_items(
|
||||||
class MikrotikEntity:
|
class MikrotikEntity:
|
||||||
"""Define entity"""
|
"""Define entity"""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
inst,
|
inst,
|
||||||
|
@ -194,17 +196,23 @@ class MikrotikEntity:
|
||||||
"""Return the name for this entity"""
|
"""Return the name for this entity"""
|
||||||
if not self._uid:
|
if not self._uid:
|
||||||
if self.entity_description.data_name_comment and self._data["comment"]:
|
if self.entity_description.data_name_comment and self._data["comment"]:
|
||||||
return f"{self._inst} {self._data['comment']}"
|
return f"{self._data['comment']}"
|
||||||
|
|
||||||
return f"{self._inst} {self.entity_description.name}"
|
return f"{self.entity_description.name}"
|
||||||
|
|
||||||
|
if self.entity_description.data_name_comment and self._data["comment"]:
|
||||||
|
return f"{self._data['comment']}"
|
||||||
|
|
||||||
if self.entity_description.name:
|
if self.entity_description.name:
|
||||||
if self.entity_description.data_name_comment and self._data["comment"]:
|
if (
|
||||||
return f"{self._inst} {self.entity_description.name} {self._data['comment']}"
|
self._data[self.entity_description.data_reference]
|
||||||
|
== self._data[self.entity_description.data_name]
|
||||||
|
):
|
||||||
|
return f"{self.entity_description.name}"
|
||||||
|
|
||||||
return f"{self._inst} {self._data[self.entity_description.data_name]} {self.entity_description.name}"
|
return f"{self._data[self.entity_description.data_name]} {self.entity_description.name}"
|
||||||
|
|
||||||
return f"{self._inst} {self._data[self.entity_description.data_name]}"
|
return f"{self._data[self.entity_description.data_name]}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
|
|
|
@ -98,7 +98,7 @@ class MikrotikClientTrafficSensor(MikrotikSensor):
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name."""
|
"""Return the name."""
|
||||||
return f"{self._data[self.entity_description.data_name]} {self.entity_description.name}"
|
return f"{self.entity_description.name}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
|
|
@ -271,7 +271,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_clients-wired": MikrotikSensorEntityDescription(
|
"system_clients-wired": MikrotikSensorEntityDescription(
|
||||||
key="system_clients-wired",
|
key="system_clients-wired",
|
||||||
name="Wired Clients",
|
name="Wired clients",
|
||||||
icon="mdi:lan",
|
icon="mdi:lan",
|
||||||
native_unit_of_measurement=None,
|
native_unit_of_measurement=None,
|
||||||
device_class=None,
|
device_class=None,
|
||||||
|
@ -286,7 +286,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_clients-wireless": MikrotikSensorEntityDescription(
|
"system_clients-wireless": MikrotikSensorEntityDescription(
|
||||||
key="system_clients-wireless",
|
key="system_clients-wireless",
|
||||||
name="Wireless Clients",
|
name="Wireless clients",
|
||||||
icon="mdi:wifi",
|
icon="mdi:wifi",
|
||||||
native_unit_of_measurement=None,
|
native_unit_of_measurement=None,
|
||||||
device_class=None,
|
device_class=None,
|
||||||
|
@ -301,7 +301,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_captive-authorized": MikrotikSensorEntityDescription(
|
"system_captive-authorized": MikrotikSensorEntityDescription(
|
||||||
key="system_captive-authorized",
|
key="system_captive-authorized",
|
||||||
name="Captive Portal Clients",
|
name="Captive portal clients",
|
||||||
icon="mdi:key-wireless",
|
icon="mdi:key-wireless",
|
||||||
native_unit_of_measurement=None,
|
native_unit_of_measurement=None,
|
||||||
device_class=None,
|
device_class=None,
|
||||||
|
@ -316,7 +316,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_gps-latitude": MikrotikSensorEntityDescription(
|
"system_gps-latitude": MikrotikSensorEntityDescription(
|
||||||
key="system_gps-latitude",
|
key="system_gps-latitude",
|
||||||
name="latitude",
|
name="Latitude",
|
||||||
icon="mdi:latitude",
|
icon="mdi:latitude",
|
||||||
native_unit_of_measurement=None,
|
native_unit_of_measurement=None,
|
||||||
device_class=None,
|
device_class=None,
|
||||||
|
@ -332,7 +332,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_gps-longitude": MikrotikSensorEntityDescription(
|
"system_gps-longitude": MikrotikSensorEntityDescription(
|
||||||
key="system_gps-longitude",
|
key="system_gps-longitude",
|
||||||
name="longitude",
|
name="Longitude",
|
||||||
icon="mdi:longitude",
|
icon="mdi:longitude",
|
||||||
native_unit_of_measurement=None,
|
native_unit_of_measurement=None,
|
||||||
device_class=None,
|
device_class=None,
|
||||||
|
@ -359,7 +359,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_attribute="tx",
|
data_attribute="tx",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
@ -378,7 +378,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_attribute="rx",
|
data_attribute="rx",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
@ -397,7 +397,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_attribute="tx-current",
|
data_attribute="tx-current",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
@ -416,7 +416,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_attribute="rx-current",
|
data_attribute="rx-current",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
|
|
@ -168,14 +168,6 @@ class MikrotikPortSwitch(MikrotikSwitch):
|
||||||
class MikrotikNATSwitch(MikrotikSwitch):
|
class MikrotikNATSwitch(MikrotikSwitch):
|
||||||
"""Representation of a NAT switch."""
|
"""Representation of a NAT switch."""
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name."""
|
|
||||||
if self._data["comment"]:
|
|
||||||
return f"{self._inst} NAT {self._data['comment']}"
|
|
||||||
|
|
||||||
return f"{self._inst} NAT {self._data['name']}"
|
|
||||||
|
|
||||||
async def async_turn_on(self) -> None:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on the switch."""
|
"""Turn on the switch."""
|
||||||
path = self.entity_description.data_switch_path
|
path = self.entity_description.data_switch_path
|
||||||
|
|
|
@ -160,7 +160,7 @@ class MikrotikSwitchEntityDescription(SwitchEntityDescription):
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
"interface": MikrotikSwitchEntityDescription(
|
"interface": MikrotikSwitchEntityDescription(
|
||||||
key="interface",
|
key="interface",
|
||||||
name="port",
|
name="Port",
|
||||||
icon_enabled="mdi:lan-connect",
|
icon_enabled="mdi:lan-connect",
|
||||||
icon_disabled="mdi:lan-pending",
|
icon_disabled="mdi:lan-pending",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -169,7 +169,7 @@ SENSOR_TYPES = {
|
||||||
ha_connection_value="data__port-mac-address",
|
ha_connection_value="data__port-mac-address",
|
||||||
data_path="interface",
|
data_path="interface",
|
||||||
data_switch_path="/interface",
|
data_switch_path="/interface",
|
||||||
data_name="name",
|
data_name="default-name",
|
||||||
data_uid="name",
|
data_uid="name",
|
||||||
data_reference="default-name",
|
data_reference="default-name",
|
||||||
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
|
||||||
|
@ -177,7 +177,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"nat": MikrotikSwitchEntityDescription(
|
"nat": MikrotikSwitchEntityDescription(
|
||||||
key="nat",
|
key="nat",
|
||||||
name="NAT",
|
name="",
|
||||||
icon_enabled="mdi:network-outline",
|
icon_enabled="mdi:network-outline",
|
||||||
icon_disabled="mdi:network-off-outline",
|
icon_disabled="mdi:network-off-outline",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -195,7 +195,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"mangle": MikrotikSwitchEntityDescription(
|
"mangle": MikrotikSwitchEntityDescription(
|
||||||
key="mangle",
|
key="mangle",
|
||||||
name="Mangle",
|
name="",
|
||||||
icon_enabled="mdi:bookmark-outline",
|
icon_enabled="mdi:bookmark-outline",
|
||||||
icon_disabled="mdi:bookmark-off-outline",
|
icon_disabled="mdi:bookmark-off-outline",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -213,7 +213,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"filter": MikrotikSwitchEntityDescription(
|
"filter": MikrotikSwitchEntityDescription(
|
||||||
key="filter",
|
key="filter",
|
||||||
name="Filter",
|
name="",
|
||||||
icon_enabled="mdi:filter-variant",
|
icon_enabled="mdi:filter-variant",
|
||||||
icon_disabled="mdi:filter-variant-remove",
|
icon_disabled="mdi:filter-variant-remove",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -247,7 +247,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"queue": MikrotikSwitchEntityDescription(
|
"queue": MikrotikSwitchEntityDescription(
|
||||||
key="queue",
|
key="queue",
|
||||||
name="Queue",
|
name="",
|
||||||
icon_enabled="mdi:leaf",
|
icon_enabled="mdi:leaf",
|
||||||
icon_disabled="mdi:leaf-off",
|
icon_disabled="mdi:leaf-off",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -264,7 +264,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"kidcontrol_enable": MikrotikSwitchEntityDescription(
|
"kidcontrol_enable": MikrotikSwitchEntityDescription(
|
||||||
key="kidcontrol_enable",
|
key="kidcontrol_enable",
|
||||||
name="kidcontrol",
|
name="",
|
||||||
icon_enabled="mdi:account",
|
icon_enabled="mdi:account",
|
||||||
icon_disabled="mdi:account-off",
|
icon_disabled="mdi:account-off",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
@ -280,7 +280,7 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"kidcontrol_pause": MikrotikSwitchEntityDescription(
|
"kidcontrol_pause": MikrotikSwitchEntityDescription(
|
||||||
key="kidcontrol_paused",
|
key="kidcontrol_paused",
|
||||||
name="kidcontrol paused",
|
name="paused",
|
||||||
icon_enabled="mdi:account-outline",
|
icon_enabled="mdi:account-outline",
|
||||||
icon_disabled="mdi:account-off-outline",
|
icon_disabled="mdi:account-off-outline",
|
||||||
entity_category=None,
|
entity_category=None,
|
||||||
|
|
|
@ -36,9 +36,9 @@ SENSOR_TYPES = {
|
||||||
),
|
),
|
||||||
"system_rbfwupdate": MikrotikUpdateEntityDescription(
|
"system_rbfwupdate": MikrotikUpdateEntityDescription(
|
||||||
key="system_rbfwupdate",
|
key="system_rbfwupdate",
|
||||||
name="RouterBoard firmware update",
|
name="RouterBOARD firmware update",
|
||||||
ha_group="System",
|
ha_group="System",
|
||||||
title="Mikrotik RouterBoard",
|
title="Mikrotik RouterBOARD",
|
||||||
data_path="routerboard",
|
data_path="routerboard",
|
||||||
data_attribute="current-firmware",
|
data_attribute="current-firmware",
|
||||||
data_name="",
|
data_name="",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue