Add Huawei LTE WiFi status binary sensors (#32553)
This commit is contained in:
parent
4c32fd12fc
commit
433b89de50
3 changed files with 85 additions and 6 deletions
|
@ -69,6 +69,7 @@ from .const import (
|
|||
KEY_NET_CURRENT_PLMN,
|
||||
KEY_NET_NET_MODE,
|
||||
KEY_WLAN_HOST_LIST,
|
||||
KEY_WLAN_WIFI_FEATURE_SWITCH,
|
||||
NOTIFY_SUPPRESS_TIMEOUT,
|
||||
SERVICE_CLEAR_TRAFFIC_STATISTICS,
|
||||
SERVICE_REBOOT,
|
||||
|
@ -243,6 +244,9 @@ class Router:
|
|||
self._get_data(KEY_NET_CURRENT_PLMN, self.client.net.current_plmn)
|
||||
self._get_data(KEY_NET_NET_MODE, self.client.net.net_mode)
|
||||
self._get_data(KEY_WLAN_HOST_LIST, self.client.wlan.host_list)
|
||||
self._get_data(
|
||||
KEY_WLAN_WIFI_FEATURE_SWITCH, self.client.wlan.wifi_feature_switch
|
||||
)
|
||||
|
||||
self.signal_update()
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.binary_sensor import (
|
|||
from homeassistant.const import CONF_URL
|
||||
|
||||
from . import HuaweiLteBaseEntity
|
||||
from .const import DOMAIN, KEY_MONITORING_STATUS
|
||||
from .const import DOMAIN, KEY_MONITORING_STATUS, KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -25,6 +25,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
|
||||
if router.data.get(KEY_MONITORING_STATUS):
|
||||
entities.append(HuaweiLteMobileConnectionBinarySensor(router))
|
||||
entities.append(HuaweiLteWifiStatusBinarySensor(router))
|
||||
entities.append(HuaweiLteWifi24ghzStatusBinarySensor(router))
|
||||
entities.append(HuaweiLteWifi5ghzStatusBinarySensor(router))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
@ -37,6 +40,15 @@ class HuaweiLteBaseBinarySensor(HuaweiLteBaseEntity, BinarySensorDevice):
|
|||
item: str
|
||||
_raw_state: Optional[str] = attr.ib(init=False, default=None)
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def _device_unique_id(self) -> str:
|
||||
return f"{self.key}.{self.item}"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to needed data on add."""
|
||||
await super().async_added_to_hass()
|
||||
|
@ -83,10 +95,6 @@ class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
|||
def _entity_name(self) -> str:
|
||||
return "Mobile connection"
|
||||
|
||||
@property
|
||||
def _device_unique_id(self) -> str:
|
||||
return f"{self.key}.{self.item}"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return whether the binary sensor is on."""
|
||||
|
@ -109,6 +117,11 @@ class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
|||
"""Return mobile connectivity sensor icon."""
|
||||
return "mdi:signal" if self.is_on else "mdi:signal-off"
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return True
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Get additional attributes related to connection status."""
|
||||
|
@ -120,3 +133,64 @@ class HuaweiLteMobileConnectionBinarySensor(HuaweiLteBaseBinarySensor):
|
|||
self._raw_state
|
||||
]
|
||||
return attributes
|
||||
|
||||
|
||||
class HuaweiLteBaseWifiStatusBinarySensor(HuaweiLteBaseBinarySensor):
|
||||
"""Huawei LTE WiFi status binary sensor base class."""
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return whether the binary sensor is on."""
|
||||
return self._raw_state is not None and int(self._raw_state) == 1
|
||||
|
||||
@property
|
||||
def assumed_state(self) -> bool:
|
||||
"""Return True if real state is assumed, not known."""
|
||||
return self._raw_state is None
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return WiFi status sensor icon."""
|
||||
return "mdi:wifi" if self.is_on else "mdi:wifi-off"
|
||||
|
||||
|
||||
@attr.s
|
||||
class HuaweiLteWifiStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||
"""Huawei LTE WiFi status binary sensor."""
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
"""Initialize identifiers."""
|
||||
self.key = KEY_MONITORING_STATUS
|
||||
self.item = "WifiStatus"
|
||||
|
||||
@property
|
||||
def _entity_name(self) -> str:
|
||||
return "WiFi status"
|
||||
|
||||
|
||||
@attr.s
|
||||
class HuaweiLteWifi24ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||
"""Huawei LTE 2.4GHz WiFi status binary sensor."""
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
"""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"
|
||||
|
||||
|
||||
@attr.s
|
||||
class HuaweiLteWifi5ghzStatusBinarySensor(HuaweiLteBaseWifiStatusBinarySensor):
|
||||
"""Huawei LTE 5GHz WiFi status binary sensor."""
|
||||
|
||||
def __attrs_post_init__(self):
|
||||
"""Initialize identifiers."""
|
||||
self.key = KEY_WLAN_WIFI_FEATURE_SWITCH
|
||||
self.item = "wifi5g_enabled"
|
||||
|
||||
@property
|
||||
def _entity_name(self) -> str:
|
||||
return "5GHz WiFi status"
|
||||
|
|
|
@ -33,8 +33,9 @@ KEY_MONITORING_TRAFFIC_STATISTICS = "monitoring_traffic_statistics"
|
|||
KEY_NET_CURRENT_PLMN = "net_current_plmn"
|
||||
KEY_NET_NET_MODE = "net_net_mode"
|
||||
KEY_WLAN_HOST_LIST = "wlan_host_list"
|
||||
KEY_WLAN_WIFI_FEATURE_SWITCH = "wlan_wifi_feature_switch"
|
||||
|
||||
BINARY_SENSOR_KEYS = {KEY_MONITORING_STATUS}
|
||||
BINARY_SENSOR_KEYS = {KEY_MONITORING_STATUS, KEY_WLAN_WIFI_FEATURE_SWITCH}
|
||||
|
||||
DEVICE_TRACKER_KEYS = {KEY_WLAN_HOST_LIST}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue