mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Don't make huawei_lte entity classes dataclasses (#106160)
This commit is contained in:
parent
fce1b6d248
commit
922cef2884
@ -616,17 +616,18 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteBaseEntity(Entity):
|
class HuaweiLteBaseEntity(Entity):
|
||||||
"""Huawei LTE entity base class."""
|
"""Huawei LTE entity base class."""
|
||||||
|
|
||||||
router: Router
|
_available = True
|
||||||
|
_attr_has_entity_name = True
|
||||||
_available: bool = field(default=True, init=False)
|
|
||||||
_unsub_handlers: list[Callable] = field(default_factory=list, init=False)
|
|
||||||
_attr_has_entity_name: bool = field(default=True, init=False)
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
|
def __init__(self, router: Router) -> None:
|
||||||
|
"""Initialize."""
|
||||||
|
self.router = router
|
||||||
|
self._unsub_handlers: list[Callable] = []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
"""Return unique ID for entity within a router."""
|
"""Return unique ID for entity within a router."""
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for Huawei LTE binary sensors."""
|
"""Support for Huawei LTE binary sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -48,15 +47,14 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteBaseBinarySensor(HuaweiLteBaseEntityWithDevice, BinarySensorEntity):
|
class HuaweiLteBaseBinarySensor(HuaweiLteBaseEntityWithDevice, BinarySensorEntity):
|
||||||
"""Huawei LTE binary sensor device base class."""
|
"""Huawei LTE binary sensor device base class."""
|
||||||
|
|
||||||
_attr_entity_registry_enabled_default = False
|
_attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
key: str = field(init=False)
|
key: str
|
||||||
item: str = field(init=False)
|
item: str
|
||||||
_raw_state: str | None = field(default=None, init=False)
|
_raw_state: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
@ -100,17 +98,14 @@ CONNECTION_STATE_ATTRIBUTES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
||||||
"""Huawei LTE mobile connection binary sensor."""
|
"""Huawei LTE mobile connection binary sensor."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="mobile_connection", init=False)
|
_attr_translation_key = "mobile_connection"
|
||||||
_attr_entity_registry_enabled_default = True
|
_attr_entity_registry_enabled_default = True
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_MONITORING_STATUS
|
||||||
"""Initialize identifiers."""
|
item = "ConnectionStatus"
|
||||||
self.key = KEY_MONITORING_STATUS
|
|
||||||
self.item = "ConnectionStatus"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
@ -165,52 +160,40 @@ class HuaweiLteBaseWifiStatusBinarySensor(HuaweiLteBaseBinarySensor):
|
|||||||
return "mdi:wifi" if self.is_on else "mdi:wifi-off"
|
return "mdi:wifi" if self.is_on else "mdi:wifi-off"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE WiFi status binary sensor."""
|
"""Huawei LTE WiFi status binary sensor."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="wifi_status", init=False)
|
_attr_translation_key: str = "wifi_status"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_MONITORING_STATUS
|
||||||
"""Initialize identifiers."""
|
item = "WifiStatus"
|
||||||
self.key = KEY_MONITORING_STATUS
|
|
||||||
self.item = "WifiStatus"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE 2.4GHz WiFi status binary sensor."""
|
"""Huawei LTE 2.4GHz WiFi status binary sensor."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="24ghz_wifi_status", init=False)
|
_attr_translation_key: str = "24ghz_wifi_status"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||||
"""Initialize identifiers."""
|
item = "wifi24g_switch_enable"
|
||||||
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
|
||||||
self.item = "wifi24g_switch_enable"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||||
"""Huawei LTE 5GHz WiFi status binary sensor."""
|
"""Huawei LTE 5GHz WiFi status binary sensor."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="5ghz_wifi_status", init=False)
|
_attr_translation_key: str = "5ghz_wifi_status"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||||
"""Initialize identifiers."""
|
item = "wifi5g_enabled"
|
||||||
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
|
||||||
self.item = "wifi5g_enabled"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteSmsStorageFullBinarySensor(HuaweiLteBaseBinarySensor):
|
class HuaweiLteSmsStorageFullBinarySensor(HuaweiLteBaseBinarySensor):
|
||||||
"""Huawei LTE SMS storage full binary sensor."""
|
"""Huawei LTE SMS storage full binary sensor."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="sms_storage_full", init=False)
|
_attr_translation_key: str = "sms_storage_full"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_MONITORING_CHECK_NOTIFICATIONS
|
||||||
"""Initialize identifiers."""
|
item = "SmsStorageFull"
|
||||||
self.key = KEY_MONITORING_CHECK_NOTIFICATIONS
|
|
||||||
self.item = "SmsStorageFull"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for device tracking of Huawei LTE routers."""
|
"""Support for device tracking of Huawei LTE routers."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
@ -173,16 +172,18 @@ def _better_snakecase(text: str) -> str:
|
|||||||
return cast(str, snakecase(text))
|
return cast(str, snakecase(text))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteScannerEntity(HuaweiLteBaseEntity, ScannerEntity):
|
class HuaweiLteScannerEntity(HuaweiLteBaseEntity, ScannerEntity):
|
||||||
"""Huawei LTE router scanner entity."""
|
"""Huawei LTE router scanner entity."""
|
||||||
|
|
||||||
_mac_address: str
|
_ip_address: str | None = None
|
||||||
|
_is_connected: bool = False
|
||||||
|
_hostname: str | None = None
|
||||||
|
|
||||||
_ip_address: str | None = field(default=None, init=False)
|
def __init__(self, router: Router, mac_address: str) -> None:
|
||||||
_is_connected: bool = field(default=False, init=False)
|
"""Initialize."""
|
||||||
_hostname: str | None = field(default=None, init=False)
|
super().__init__(router)
|
||||||
_extra_state_attributes: dict[str, Any] = field(default_factory=dict, init=False)
|
self._extra_state_attributes: dict[str, Any] = {}
|
||||||
|
self._mac_address = mac_address
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for Huawei LTE router notifications."""
|
"""Support for Huawei LTE router notifications."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -34,12 +33,13 @@ async def async_get_service(
|
|||||||
return HuaweiLteSmsNotificationService(router, default_targets)
|
return HuaweiLteSmsNotificationService(router, default_targets)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteSmsNotificationService(BaseNotificationService):
|
class HuaweiLteSmsNotificationService(BaseNotificationService):
|
||||||
"""Huawei LTE router SMS notification service."""
|
"""Huawei LTE router SMS notification service."""
|
||||||
|
|
||||||
router: Router
|
def __init__(self, router: Router, default_targets: list[str]) -> None:
|
||||||
default_targets: list[str]
|
"""Initialize."""
|
||||||
|
self.router = router
|
||||||
|
self.default_targets = default_targets
|
||||||
|
|
||||||
def send_message(self, message: str = "", **kwargs: Any) -> None:
|
def send_message(self, message: str = "", **kwargs: Any) -> None:
|
||||||
"""Send message to target numbers."""
|
"""Send message to target numbers."""
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import UNDEFINED
|
from homeassistant.helpers.typing import UNDEFINED
|
||||||
|
|
||||||
from . import HuaweiLteBaseEntityWithDevice
|
from . import HuaweiLteBaseEntityWithDevice, Router
|
||||||
from .const import DOMAIN, KEY_NET_NET_MODE
|
from .const import DOMAIN, KEY_NET_NET_MODE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -80,18 +80,25 @@ async def async_setup_entry(
|
|||||||
async_add_entities(selects, True)
|
async_add_entities(selects, True)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteSelectEntity(HuaweiLteBaseEntityWithDevice, SelectEntity):
|
class HuaweiLteSelectEntity(HuaweiLteBaseEntityWithDevice, SelectEntity):
|
||||||
"""Huawei LTE select entity."""
|
"""Huawei LTE select entity."""
|
||||||
|
|
||||||
entity_description: HuaweiSelectEntityDescription
|
entity_description: HuaweiSelectEntityDescription
|
||||||
key: str
|
_raw_state: str | None = None
|
||||||
item: str
|
|
||||||
|
|
||||||
_raw_state: str | None = field(default=None, init=False)
|
def __init__(
|
||||||
|
self,
|
||||||
|
router: Router,
|
||||||
|
entity_description: HuaweiSelectEntityDescription,
|
||||||
|
key: str,
|
||||||
|
item: str,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize."""
|
||||||
|
super().__init__(router)
|
||||||
|
self.entity_description = entity_description
|
||||||
|
self.key = key
|
||||||
|
self.item = item
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
|
||||||
"""Initialize remaining attributes."""
|
|
||||||
name = None
|
name = None
|
||||||
if self.entity_description.name != UNDEFINED:
|
if self.entity_description.name != UNDEFINED:
|
||||||
name = self.entity_description.name
|
name = self.entity_description.name
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
from collections.abc import Callable, Sequence
|
from collections.abc import Callable, Sequence
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@ -29,7 +29,7 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import HuaweiLteBaseEntityWithDevice
|
from . import HuaweiLteBaseEntityWithDevice, Router
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
KEY_DEVICE_INFORMATION,
|
KEY_DEVICE_INFORMATION,
|
||||||
@ -688,17 +688,26 @@ async def async_setup_entry(
|
|||||||
async_add_entities(sensors, True)
|
async_add_entities(sensors, True)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity):
|
class HuaweiLteSensor(HuaweiLteBaseEntityWithDevice, SensorEntity):
|
||||||
"""Huawei LTE sensor entity."""
|
"""Huawei LTE sensor entity."""
|
||||||
|
|
||||||
key: str
|
|
||||||
item: str
|
|
||||||
entity_description: HuaweiSensorEntityDescription
|
entity_description: HuaweiSensorEntityDescription
|
||||||
|
_state: StateType = None
|
||||||
|
_unit: str | None = None
|
||||||
|
_last_reset: datetime | None = None
|
||||||
|
|
||||||
_state: StateType = field(default=None, init=False)
|
def __init__(
|
||||||
_unit: str | None = field(default=None, init=False)
|
self,
|
||||||
_last_reset: datetime | None = field(default=None, init=False)
|
router: Router,
|
||||||
|
key: str,
|
||||||
|
item: str,
|
||||||
|
entity_description: HuaweiSensorEntityDescription,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize."""
|
||||||
|
super().__init__(router)
|
||||||
|
self.key = key
|
||||||
|
self.item = item
|
||||||
|
self.entity_description = entity_description
|
||||||
|
|
||||||
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."""
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""Support for Huawei LTE switches."""
|
"""Support for Huawei LTE switches."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -43,17 +42,14 @@ async def async_setup_entry(
|
|||||||
async_add_entities(switches, True)
|
async_add_entities(switches, True)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity):
|
class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity):
|
||||||
"""Huawei LTE switch device base class."""
|
"""Huawei LTE switch device base class."""
|
||||||
|
|
||||||
key: str = field(init=False)
|
key: str
|
||||||
item: str = field(init=False)
|
item: str
|
||||||
|
|
||||||
_attr_device_class: SwitchDeviceClass = field(
|
_attr_device_class: SwitchDeviceClass = SwitchDeviceClass.SWITCH
|
||||||
default=SwitchDeviceClass.SWITCH, init=False
|
_raw_state: str | None = None
|
||||||
)
|
|
||||||
_raw_state: str | None = field(default=None, init=False)
|
|
||||||
|
|
||||||
def _turn(self, state: bool) -> None:
|
def _turn(self, state: bool) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -88,16 +84,13 @@ class HuaweiLteBaseSwitch(HuaweiLteBaseEntityWithDevice, SwitchEntity):
|
|||||||
self._raw_state = str(value)
|
self._raw_state = str(value)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
||||||
"""Huawei LTE mobile data switch device."""
|
"""Huawei LTE mobile data switch device."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="mobile_data", init=False)
|
_attr_translation_key: str = "mobile_data"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_DIALUP_MOBILE_DATASWITCH
|
||||||
"""Initialize identifiers."""
|
item = "dataswitch"
|
||||||
self.key = KEY_DIALUP_MOBILE_DATASWITCH
|
|
||||||
self.item = "dataswitch"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
@ -120,16 +113,13 @@ class HuaweiLteMobileDataSwitch(HuaweiLteBaseSwitch):
|
|||||||
return "mdi:signal" if self.is_on else "mdi:signal-off"
|
return "mdi:signal" if self.is_on else "mdi:signal-off"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch):
|
class HuaweiLteWifiGuestNetworkSwitch(HuaweiLteBaseSwitch):
|
||||||
"""Huawei LTE WiFi guest network switch device."""
|
"""Huawei LTE WiFi guest network switch device."""
|
||||||
|
|
||||||
_attr_translation_key: str = field(default="wifi_guest_network", init=False)
|
_attr_translation_key: str = "wifi_guest_network"
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH
|
||||||
"""Initialize identifiers."""
|
item = "WifiEnable"
|
||||||
self.key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH
|
|
||||||
self.item = "WifiEnable"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _device_unique_id(self) -> str:
|
def _device_unique_id(self) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user