Migrated to new entity naming style

This commit is contained in:
Tomaae 2022-08-18 09:29:55 +02:00
parent 1a0861fd9c
commit 0b4a7a3c72
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0
8 changed files with 37 additions and 37 deletions

View file

@ -137,7 +137,7 @@ SENSOR_TYPES = {
),
"interface": MikrotikBinarySensorEntityDescription(
key="interface",
name="",
name="Connection",
icon_enabled="mdi:lan-connect",
icon_disabled="mdi:lan-pending",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
@ -146,7 +146,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="running",
data_name="name",
data_name="default-name",
data_uid="default-name",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,

View file

@ -99,7 +99,7 @@ class MikrotikHostDeviceTracker(MikrotikDeviceTracker):
@property
def name(self) -> str:
"""Return the name."""
return f"{self._data[self.entity_description.data_name]}"
return ""
@property
def is_connected(self) -> bool:

View file

@ -168,6 +168,8 @@ def model_update_items(
class MikrotikEntity:
"""Define entity"""
_attr_has_entity_name = True
def __init__(
self,
inst,
@ -194,17 +196,23 @@ class MikrotikEntity:
"""Return the name for this entity"""
if not self._uid:
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.data_name_comment and self._data["comment"]:
return f"{self._inst} {self.entity_description.name} {self._data['comment']}"
if (
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
def unique_id(self) -> str:

View file

@ -98,7 +98,7 @@ class MikrotikClientTrafficSensor(MikrotikSensor):
@property
def name(self) -> str:
"""Return the name."""
return f"{self._data[self.entity_description.data_name]} {self.entity_description.name}"
return f"{self.entity_description.name}"
@property
def available(self) -> bool:

View file

@ -271,7 +271,7 @@ SENSOR_TYPES = {
),
"system_clients-wired": MikrotikSensorEntityDescription(
key="system_clients-wired",
name="Wired Clients",
name="Wired clients",
icon="mdi:lan",
native_unit_of_measurement=None,
device_class=None,
@ -286,7 +286,7 @@ SENSOR_TYPES = {
),
"system_clients-wireless": MikrotikSensorEntityDescription(
key="system_clients-wireless",
name="Wireless Clients",
name="Wireless clients",
icon="mdi:wifi",
native_unit_of_measurement=None,
device_class=None,
@ -301,7 +301,7 @@ SENSOR_TYPES = {
),
"system_captive-authorized": MikrotikSensorEntityDescription(
key="system_captive-authorized",
name="Captive Portal Clients",
name="Captive portal clients",
icon="mdi:key-wireless",
native_unit_of_measurement=None,
device_class=None,
@ -316,7 +316,7 @@ SENSOR_TYPES = {
),
"system_gps-latitude": MikrotikSensorEntityDescription(
key="system_gps-latitude",
name="latitude",
name="Latitude",
icon="mdi:latitude",
native_unit_of_measurement=None,
device_class=None,
@ -332,7 +332,7 @@ SENSOR_TYPES = {
),
"system_gps-longitude": MikrotikSensorEntityDescription(
key="system_gps-longitude",
name="longitude",
name="Longitude",
icon="mdi:longitude",
native_unit_of_measurement=None,
device_class=None,
@ -359,7 +359,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="tx",
data_name="name",
data_name="default-name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
@ -378,7 +378,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="rx",
data_name="name",
data_name="default-name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
@ -397,7 +397,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="tx-current",
data_name="name",
data_name="default-name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
@ -416,7 +416,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_attribute="rx-current",
data_name="name",
data_name="default-name",
data_uid="",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,

View file

@ -168,14 +168,6 @@ class MikrotikPortSwitch(MikrotikSwitch):
class MikrotikNATSwitch(MikrotikSwitch):
"""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:
"""Turn on the switch."""
path = self.entity_description.data_switch_path

View file

@ -160,7 +160,7 @@ class MikrotikSwitchEntityDescription(SwitchEntityDescription):
SENSOR_TYPES = {
"interface": MikrotikSwitchEntityDescription(
key="interface",
name="port",
name="Port",
icon_enabled="mdi:lan-connect",
icon_disabled="mdi:lan-pending",
entity_category=None,
@ -169,7 +169,7 @@ SENSOR_TYPES = {
ha_connection_value="data__port-mac-address",
data_path="interface",
data_switch_path="/interface",
data_name="name",
data_name="default-name",
data_uid="name",
data_reference="default-name",
data_attributes_list=DEVICE_ATTRIBUTES_IFACE,
@ -177,7 +177,7 @@ SENSOR_TYPES = {
),
"nat": MikrotikSwitchEntityDescription(
key="nat",
name="NAT",
name="",
icon_enabled="mdi:network-outline",
icon_disabled="mdi:network-off-outline",
entity_category=None,
@ -195,7 +195,7 @@ SENSOR_TYPES = {
),
"mangle": MikrotikSwitchEntityDescription(
key="mangle",
name="Mangle",
name="",
icon_enabled="mdi:bookmark-outline",
icon_disabled="mdi:bookmark-off-outline",
entity_category=None,
@ -213,7 +213,7 @@ SENSOR_TYPES = {
),
"filter": MikrotikSwitchEntityDescription(
key="filter",
name="Filter",
name="",
icon_enabled="mdi:filter-variant",
icon_disabled="mdi:filter-variant-remove",
entity_category=None,
@ -247,7 +247,7 @@ SENSOR_TYPES = {
),
"queue": MikrotikSwitchEntityDescription(
key="queue",
name="Queue",
name="",
icon_enabled="mdi:leaf",
icon_disabled="mdi:leaf-off",
entity_category=None,
@ -264,7 +264,7 @@ SENSOR_TYPES = {
),
"kidcontrol_enable": MikrotikSwitchEntityDescription(
key="kidcontrol_enable",
name="kidcontrol",
name="",
icon_enabled="mdi:account",
icon_disabled="mdi:account-off",
entity_category=None,
@ -280,7 +280,7 @@ SENSOR_TYPES = {
),
"kidcontrol_pause": MikrotikSwitchEntityDescription(
key="kidcontrol_paused",
name="kidcontrol paused",
name="paused",
icon_enabled="mdi:account-outline",
icon_disabled="mdi:account-off-outline",
entity_category=None,

View file

@ -36,9 +36,9 @@ SENSOR_TYPES = {
),
"system_rbfwupdate": MikrotikUpdateEntityDescription(
key="system_rbfwupdate",
name="RouterBoard firmware update",
name="RouterBOARD firmware update",
ha_group="System",
title="Mikrotik RouterBoard",
title="Mikrotik RouterBOARD",
data_path="routerboard",
data_attribute="current-firmware",
data_name="",