diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index 3ca3daff523..bace633f128 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -586,10 +586,7 @@ class HuaweiLteBaseEntity(Entity): _available: bool = field(default=True, init=False) _unsub_handlers: list[Callable] = field(default_factory=list, init=False) - - @property - def _entity_name(self) -> str: - raise NotImplementedError + _attr_has_entity_name: bool = field(default=True, init=False) @property def _device_unique_id(self) -> str: @@ -601,11 +598,6 @@ class HuaweiLteBaseEntity(Entity): """Return unique ID for entity.""" return f"{self.router.config_entry.unique_id}-{self._device_unique_id}" - @property - def name(self) -> str: - """Return entity name.""" - return f"Huawei {self.router.device_name} {self._entity_name}" - @property def available(self) -> bool: """Return whether the entity is available.""" diff --git a/homeassistant/components/huawei_lte/binary_sensor.py b/homeassistant/components/huawei_lte/binary_sensor.py index 9bd455d9d59..695b7e2e815 100644 --- a/homeassistant/components/huawei_lte/binary_sensor.py +++ b/homeassistant/components/huawei_lte/binary_sensor.py @@ -105,15 +105,13 @@ CONNECTION_STATE_ATTRIBUTES = { class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor): """Huawei LTE mobile connection binary sensor.""" + _attr_name: str = field(default="Mobile connection", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_MONITORING_STATUS self.item = "ConnectionStatus" - @property - def _entity_name(self) -> str: - return "Mobile connection" - @property def is_on(self) -> bool: """Return whether the binary sensor is on.""" @@ -176,57 +174,49 @@ class HuaweiLteBaseWifiStatusBinarySensor(HuaweiLteBaseBinarySensor): class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor): """Huawei LTE WiFi status binary sensor.""" + _attr_name: str = field(default="WiFi status", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_MONITORING_STATUS self.item = "WifiStatus" - @property - def _entity_name(self) -> str: - return "WiFi status" - @dataclass class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor): """Huawei LTE 2.4GHz WiFi status binary sensor.""" + _attr_name: str = field(default="2.4GHz WiFi status", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_WLAN_WIFI_FEATURE_SWITCH self.item = "wifi24g_switch_enable" - @property - def _entity_name(self) -> str: - return "2.4GHz WiFi status" - @dataclass class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor): """Huawei LTE 5GHz WiFi status binary sensor.""" + _attr_name: str = field(default="5GHz WiFi status", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_WLAN_WIFI_FEATURE_SWITCH self.item = "wifi5g_enabled" - @property - def _entity_name(self) -> str: - return "5GHz WiFi status" - @dataclass class HuaweiLteSmsStorageFullBinarySensor(HuaweiLteBaseBinarySensor): """Huawei LTE SMS storage full binary sensor.""" + _attr_name: str = field(default="SMS storage full", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_MONITORING_CHECK_NOTIFICATIONS self.item = "SmsStorageFull" - @property - def _entity_name(self) -> str: - return "SMS storage full" - @property def is_on(self) -> bool: """Return whether the binary sensor is on.""" diff --git a/homeassistant/components/huawei_lte/device_tracker.py b/homeassistant/components/huawei_lte/device_tracker.py index ee643c59b12..179587d72d7 100644 --- a/homeassistant/components/huawei_lte/device_tracker.py +++ b/homeassistant/components/huawei_lte/device_tracker.py @@ -185,7 +185,8 @@ class HuaweiLteScannerEntity(HuaweiLteBaseEntity, ScannerEntity): _extra_state_attributes: dict[str, Any] = field(default_factory=dict, init=False) @property - def _entity_name(self) -> str: + def name(self) -> str: + """Return the name of the entity.""" return self.hostname or self.mac_address @property diff --git a/homeassistant/components/huawei_lte/sensor.py b/homeassistant/components/huawei_lte/sensor.py index 642d8368207..44d03677ebd 100644 --- a/homeassistant/components/huawei_lte/sensor.py +++ b/homeassistant/components/huawei_lte/sensor.py @@ -548,6 +548,10 @@ class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity): _state: StateType = field(default=STATE_UNKNOWN, init=False) _unit: str | None = field(default=None, init=False) + def __post_init__(self) -> None: + """Initialize remaining attributes.""" + self._attr_name = self.meta.name or self.item + async def async_added_to_hass(self) -> None: """Subscribe to needed data on add.""" await super().async_added_to_hass() @@ -558,10 +562,6 @@ class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity): await super().async_will_remove_from_hass() self.router.subscriptions[self.key].remove(f"{SENSOR_DOMAIN}/{self.item}") - @property - def _entity_name(self) -> str: - return self.meta.name or self.item - @property def _device_unique_id(self) -> str: return f"{self.key}.{self.item}" diff --git a/homeassistant/components/huawei_lte/switch.py b/homeassistant/components/huawei_lte/switch.py index 611f7212d9a..78579d62698 100644 --- a/homeassistant/components/huawei_lte/switch.py +++ b/homeassistant/components/huawei_lte/switch.py @@ -92,15 +92,13 @@ class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity): class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch): """Huawei LTE mobile data switch device.""" + _attr_name: str = field(default="Mobile data", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_DIALUP_MOBILE_DATASWITCH self.item = "dataswitch" - @property - def _entity_name(self) -> str: - return "Mobile data" - @property def _device_unique_id(self) -> str: return f"{self.key}.{self.item}" @@ -126,15 +124,13 @@ class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch): class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch): """Huawei LTE WiFi guest network switch device.""" + _attr_name: str = field(default="WiFi guest network", init=False) + def __post_init__(self) -> None: """Initialize identifiers.""" self.key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH self.item = "WifiEnable" - @property - def _entity_name(self) -> str: - return "WiFi guest network" - @property def _device_unique_id(self) -> str: return f"{self.key}.{self.item}" diff --git a/tests/components/huawei_lte/test_switches.py b/tests/components/huawei_lte/test_switches.py index c5006add923..5bafed27e70 100644 --- a/tests/components/huawei_lte/test_switches.py +++ b/tests/components/huawei_lte/test_switches.py @@ -17,7 +17,7 @@ from homeassistant.helpers.entity_registry import EntityRegistry from tests.common import MockConfigEntry -SWITCH_WIFI_GUEST_NETWORK = "switch.huawei_lte_wifi_guest_network" +SWITCH_WIFI_GUEST_NETWORK = "switch.lte_wifi_guest_network" @fixture