mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Huawei LTE cleanups (#48959)
This commit is contained in:
parent
441c304f11
commit
4149cc9662
@ -48,11 +48,7 @@ from homeassistant.helpers import (
|
||||
device_registry as dr,
|
||||
discovery,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
@ -82,7 +78,6 @@ from .const import (
|
||||
SERVICE_REBOOT,
|
||||
SERVICE_RESUME_INTEGRATION,
|
||||
SERVICE_SUSPEND_INTEGRATION,
|
||||
UPDATE_OPTIONS_SIGNAL,
|
||||
UPDATE_SIGNAL,
|
||||
)
|
||||
|
||||
@ -436,11 +431,6 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
|
||||
hass.data[DOMAIN].hass_config,
|
||||
)
|
||||
|
||||
# Add config entry options update listener
|
||||
router.unload_handlers.append(
|
||||
config_entry.add_update_listener(async_signal_options_update)
|
||||
)
|
||||
|
||||
def _update_router(*_: Any) -> None:
|
||||
"""
|
||||
Update router data.
|
||||
@ -492,9 +482,8 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||
|
||||
def service_handler(service: ServiceCall) -> None:
|
||||
"""Apply a service."""
|
||||
url = service.data.get(CONF_URL)
|
||||
routers = hass.data[DOMAIN].routers
|
||||
if url:
|
||||
if url := service.data.get(CONF_URL):
|
||||
router = routers.get(url)
|
||||
elif not routers:
|
||||
_LOGGER.error("%s: no routers configured", service.service)
|
||||
@ -559,13 +548,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_signal_options_update(
|
||||
hass: HomeAssistantType, config_entry: ConfigEntry
|
||||
) -> None:
|
||||
"""Handle config entry options update."""
|
||||
async_dispatcher_send(hass, UPDATE_OPTIONS_SIGNAL, config_entry)
|
||||
|
||||
|
||||
async def async_migrate_entry(
|
||||
hass: HomeAssistantType, config_entry: ConfigEntry
|
||||
) -> bool:
|
||||
@ -631,30 +613,17 @@ class HuaweiLteBaseEntity(Entity):
|
||||
"""Update state."""
|
||||
raise NotImplementedError
|
||||
|
||||
async def async_update_options(self, config_entry: ConfigEntry) -> None:
|
||||
"""Update config entry options."""
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Connect to update signals."""
|
||||
self._unsub_handlers.append(
|
||||
async_dispatcher_connect(self.hass, UPDATE_SIGNAL, self._async_maybe_update)
|
||||
)
|
||||
self._unsub_handlers.append(
|
||||
async_dispatcher_connect(
|
||||
self.hass, UPDATE_OPTIONS_SIGNAL, self._async_maybe_update_options
|
||||
)
|
||||
)
|
||||
|
||||
async def _async_maybe_update(self, url: str) -> None:
|
||||
"""Update state if the update signal comes from our router."""
|
||||
if url == self.router.url:
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def _async_maybe_update_options(self, config_entry: ConfigEntry) -> None:
|
||||
"""Update options if the update signal comes from our router."""
|
||||
if config_entry.data[CONF_URL] == self.router.url:
|
||||
await self.async_update_options(config_entry)
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Invoke unsubscription handlers."""
|
||||
for unsub in self._unsub_handlers:
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""Config flow for the Huawei LTE platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
from typing import Any
|
||||
from urllib.parse import urlparse
|
||||
@ -65,32 +64,21 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
OrderedDict(
|
||||
(
|
||||
(
|
||||
vol.Required(
|
||||
CONF_URL,
|
||||
default=user_input.get(
|
||||
CONF_URL,
|
||||
self.context.get(CONF_URL, ""),
|
||||
),
|
||||
),
|
||||
str,
|
||||
{
|
||||
vol.Required(
|
||||
CONF_URL,
|
||||
default=user_input.get(
|
||||
CONF_URL,
|
||||
self.context.get(CONF_URL, ""),
|
||||
),
|
||||
(
|
||||
vol.Optional(
|
||||
CONF_USERNAME, default=user_input.get(CONF_USERNAME, "")
|
||||
),
|
||||
str,
|
||||
),
|
||||
(
|
||||
vol.Optional(
|
||||
CONF_PASSWORD, default=user_input.get(CONF_PASSWORD, "")
|
||||
),
|
||||
str,
|
||||
),
|
||||
)
|
||||
)
|
||||
): str,
|
||||
vol.Optional(
|
||||
CONF_USERNAME, default=user_input.get(CONF_USERNAME, "")
|
||||
): str,
|
||||
vol.Optional(
|
||||
CONF_PASSWORD, default=user_input.get(CONF_PASSWORD, "")
|
||||
): str,
|
||||
}
|
||||
),
|
||||
errors=errors or {},
|
||||
)
|
||||
|
@ -6,7 +6,6 @@ DEFAULT_DEVICE_NAME = "LTE"
|
||||
DEFAULT_NOTIFY_SERVICE_NAME = DOMAIN
|
||||
|
||||
UPDATE_SIGNAL = f"{DOMAIN}_update"
|
||||
UPDATE_OPTIONS_SIGNAL = f"{DOMAIN}_options_update"
|
||||
|
||||
CONNECTION_TIMEOUT = 10
|
||||
NOTIFY_SUPPRESS_TIMEOUT = 30
|
||||
|
@ -105,6 +105,7 @@ def async_add_new_entities(
|
||||
|
||||
|
||||
def _better_snakecase(text: str) -> str:
|
||||
# Awaiting https://github.com/okunishinishi/python-stringcase/pull/18
|
||||
if text == text.upper():
|
||||
# All uppercase to all lowercase to get http for HTTP, not h_t_t_p
|
||||
text = text.lower()
|
||||
|
@ -337,11 +337,9 @@ async def async_setup_entry(
|
||||
router = hass.data[DOMAIN].routers[config_entry.data[CONF_URL]]
|
||||
sensors: list[Entity] = []
|
||||
for key in SENSOR_KEYS:
|
||||
items = router.data.get(key)
|
||||
if not items:
|
||||
if not (items := router.data.get(key)):
|
||||
continue
|
||||
key_meta = SENSOR_META.get(key)
|
||||
if key_meta:
|
||||
if key_meta := SENSOR_META.get(key):
|
||||
if key_meta.include:
|
||||
items = filter(key_meta.include.search, items)
|
||||
if key_meta.exclude:
|
||||
@ -361,10 +359,9 @@ def format_default(value: StateType) -> tuple[StateType, str | None]:
|
||||
unit = None
|
||||
if value is not None:
|
||||
# Clean up value and infer unit, e.g. -71dBm, 15 dB
|
||||
match = re.match(
|
||||
if match := re.match(
|
||||
r"([>=<]*)(?P<value>.+?)\s*(?P<unit>[a-zA-Z]+)\s*$", str(value)
|
||||
)
|
||||
if match:
|
||||
):
|
||||
try:
|
||||
value = float(match.group("value"))
|
||||
unit = match.group("unit")
|
||||
|
@ -33,8 +33,7 @@
|
||||
"init": {
|
||||
"data": {
|
||||
"name": "Notification service name (change requires restart)",
|
||||
"recipient": "SMS notification recipients",
|
||||
"track_new_devices": "Track new devices"
|
||||
"recipient": "SMS notification recipients"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user