mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Migrate Huawei LTE to new entity naming style (#75303)
This commit is contained in:
parent
079460d2dd
commit
b749622c01
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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
|
||||
|
@ -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}"
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user