mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +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)
|
_available: bool = field(default=True, init=False)
|
||||||
_unsub_handlers: list[Callable] = field(default_factory=list, init=False)
|
_unsub_handlers: list[Callable] = field(default_factory=list, init=False)
|
||||||
|
_attr_has_entity_name: bool = field(default=True, init=False)
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
@ -601,11 +598,6 @@ class HuaweiLteBaseEntity(Entity):
|
|||||||
"""Return unique ID for entity."""
|
"""Return unique ID for entity."""
|
||||||
return f"{self.router.config_entry.unique_id}-{self._device_unique_id}"
|
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
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return whether the entity is available."""
|
"""Return whether the entity is available."""
|
||||||
|
@ -105,15 +105,13 @@ CONNECTION_STATE_ATTRIBUTES = {
|
|||||||
class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
||||||
"""Huawei LTE mobile connection binary sensor."""
|
"""Huawei LTE mobile connection binary sensor."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="Mobile connection", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_MONITORING_STATUS
|
self.key = KEY_MONITORING_STATUS
|
||||||
self.item = "ConnectionStatus"
|
self.item = "ConnectionStatus"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "Mobile connection"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return whether the binary sensor is on."""
|
"""Return whether the binary sensor is on."""
|
||||||
@ -176,57 +174,49 @@ class HuaweiLteBaseWifiStatusBinarySensor(HuaweiLteBaseBinarySensor):
|
|||||||
class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE WiFi status binary sensor."""
|
"""Huawei LTE WiFi status binary sensor."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="WiFi status", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_MONITORING_STATUS
|
self.key = KEY_MONITORING_STATUS
|
||||||
self.item = "WifiStatus"
|
self.item = "WifiStatus"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "WiFi status"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE 2.4GHz WiFi status binary sensor."""
|
"""Huawei LTE 2.4GHz WiFi status binary sensor."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="2.4GHz WiFi status", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||||
self.item = "wifi24g_switch_enable"
|
self.item = "wifi24g_switch_enable"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "2.4GHz WiFi status"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE 5GHz WiFi status binary sensor."""
|
"""Huawei LTE 5GHz WiFi status binary sensor."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="5GHz WiFi status", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||||
self.item = "wifi5g_enabled"
|
self.item = "wifi5g_enabled"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "5GHz WiFi status"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class HuaweiLteSmsStorageFullBinarySensor(HuaweiLteBaseBinarySensor):
|
class HuaweiLteSmsStorageFullBinarySensor(HuaweiLteBaseBinarySensor):
|
||||||
"""Huawei LTE SMS storage full binary sensor."""
|
"""Huawei LTE SMS storage full binary sensor."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="SMS storage full", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_MONITORING_CHECK_NOTIFICATIONS
|
self.key = KEY_MONITORING_CHECK_NOTIFICATIONS
|
||||||
self.item = "SmsStorageFull"
|
self.item = "SmsStorageFull"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "SMS storage full"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return whether the binary sensor is on."""
|
"""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)
|
_extra_state_attributes: dict[str, Any] = field(default_factory=dict, init=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _entity_name(self) -> str:
|
def name(self) -> str:
|
||||||
|
"""Return the name of the entity."""
|
||||||
return self.hostname or self.mac_address
|
return self.hostname or self.mac_address
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -548,6 +548,10 @@ class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity):
|
|||||||
_state: StateType = field(default=STATE_UNKNOWN, init=False)
|
_state: StateType = field(default=STATE_UNKNOWN, init=False)
|
||||||
_unit: str | None = field(default=None, 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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to needed data on add."""
|
"""Subscribe to needed data on add."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
@ -558,10 +562,6 @@ class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity):
|
|||||||
await super().async_will_remove_from_hass()
|
await super().async_will_remove_from_hass()
|
||||||
self.router.subscriptions[self.key].remove(f"{SENSOR_DOMAIN}/{self.item}")
|
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
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
return f"{self.key}.{self.item}"
|
return f"{self.key}.{self.item}"
|
||||||
|
@ -92,15 +92,13 @@ class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity):
|
|||||||
class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
||||||
"""Huawei LTE mobile data switch device."""
|
"""Huawei LTE mobile data switch device."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="Mobile data", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_DIALUP_MOBILE_DATASWITCH
|
self.key = KEY_DIALUP_MOBILE_DATASWITCH
|
||||||
self.item = "dataswitch"
|
self.item = "dataswitch"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "Mobile data"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
return f"{self.key}.{self.item}"
|
return f"{self.key}.{self.item}"
|
||||||
@ -126,15 +124,13 @@ class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
|||||||
class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch):
|
class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch):
|
||||||
"""Huawei LTE WiFi guest network switch device."""
|
"""Huawei LTE WiFi guest network switch device."""
|
||||||
|
|
||||||
|
_attr_name: str = field(default="WiFi guest network", init=False)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""Initialize identifiers."""
|
"""Initialize identifiers."""
|
||||||
self.key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH
|
self.key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH
|
||||||
self.item = "WifiEnable"
|
self.item = "WifiEnable"
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self) -> str:
|
|
||||||
return "WiFi guest network"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
return f"{self.key}.{self.item}"
|
return f"{self.key}.{self.item}"
|
||||||
|
@ -17,7 +17,7 @@ from homeassistant.helpers.entity_registry import EntityRegistry
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry
|
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
|
@fixture
|
||||||
|
Loading…
x
Reference in New Issue
Block a user