Use local constant in netgear_lte config schema (#63753)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/63827/head
parent
d1bb916070
commit
c370a4b987
|
@ -2,15 +2,13 @@
|
|||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Final
|
||||
|
||||
import aiohttp
|
||||
import attr
|
||||
import eternalegypt
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
|
@ -38,6 +36,10 @@ _LOGGER = logging.getLogger(__name__)
|
|||
SCAN_INTERVAL = timedelta(seconds=10)
|
||||
DISPATCHER_NETGEAR_LTE = "netgear_lte_update"
|
||||
|
||||
CONF_NOTIFY: Final = "notify"
|
||||
CONF_BINARY_SENSOR: Final = "binary_sensor"
|
||||
CONF_SENSOR: Final = "sensor"
|
||||
|
||||
DOMAIN = "netgear_lte"
|
||||
DATA_KEY = "netgear_lte"
|
||||
|
||||
|
@ -91,12 +93,12 @@ CONFIG_SCHEMA = vol.Schema(
|
|||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(NOTIFY_DOMAIN, default={}): vol.All(
|
||||
vol.Optional(CONF_NOTIFY, default={}): vol.All(
|
||||
cv.ensure_list, [NOTIFY_SCHEMA]
|
||||
),
|
||||
vol.Optional(SENSOR_DOMAIN, default={}): SENSOR_SCHEMA,
|
||||
vol.Optional(CONF_SENSOR, default={}): SENSOR_SCHEMA,
|
||||
vol.Optional(
|
||||
BINARY_SENSOR_DOMAIN, default={}
|
||||
CONF_BINARY_SENSOR, default={}
|
||||
): BINARY_SENSOR_SCHEMA,
|
||||
}
|
||||
)
|
||||
|
@ -225,11 +227,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
# Load platforms for each modem
|
||||
for lte_conf in netgear_lte_config:
|
||||
# Notify
|
||||
for notify_conf in lte_conf[NOTIFY_DOMAIN]:
|
||||
for notify_conf in lte_conf[CONF_NOTIFY]:
|
||||
discovery_info = {
|
||||
CONF_HOST: lte_conf[CONF_HOST],
|
||||
CONF_NAME: notify_conf.get(CONF_NAME),
|
||||
NOTIFY_DOMAIN: notify_conf,
|
||||
CONF_NOTIFY: notify_conf,
|
||||
}
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
|
@ -238,8 +240,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
)
|
||||
|
||||
# Sensor
|
||||
sensor_conf = lte_conf.get(SENSOR_DOMAIN)
|
||||
discovery_info = {CONF_HOST: lte_conf[CONF_HOST], SENSOR_DOMAIN: sensor_conf}
|
||||
sensor_conf = lte_conf[CONF_SENSOR]
|
||||
discovery_info = {CONF_HOST: lte_conf[CONF_HOST], CONF_SENSOR: sensor_conf}
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
hass, Platform.SENSOR, DOMAIN, discovery_info, config
|
||||
|
@ -247,10 +249,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
)
|
||||
|
||||
# Binary Sensor
|
||||
binary_sensor_conf = lte_conf.get(BINARY_SENSOR_DOMAIN)
|
||||
binary_sensor_conf = lte_conf[CONF_BINARY_SENSOR]
|
||||
discovery_info = {
|
||||
CONF_HOST: lte_conf[CONF_HOST],
|
||||
BINARY_SENSOR_DOMAIN: binary_sensor_conf,
|
||||
CONF_BINARY_SENSOR: binary_sensor_conf,
|
||||
}
|
||||
hass.async_create_task(
|
||||
discovery.async_load_platform(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""Support for Netgear LTE binary sensors."""
|
||||
from homeassistant.components.binary_sensor import DOMAIN, BinarySensorEntity
|
||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
||||
from . import CONF_MONITORED_CONDITIONS, DATA_KEY, LTEEntity
|
||||
from . import CONF_BINARY_SENSOR, CONF_MONITORED_CONDITIONS, DATA_KEY, LTEEntity
|
||||
from .sensor_types import BINARY_SENSOR_CLASSES
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info)
|
|||
if not modem_data or not modem_data.data:
|
||||
raise PlatformNotReady
|
||||
|
||||
binary_sensor_conf = discovery_info[DOMAIN]
|
||||
binary_sensor_conf = discovery_info[CONF_BINARY_SENSOR]
|
||||
monitored_conditions = binary_sensor_conf[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
binary_sensors = []
|
||||
|
|
|
@ -4,9 +4,9 @@ import logging
|
|||
import attr
|
||||
import eternalegypt
|
||||
|
||||
from homeassistant.components.notify import ATTR_TARGET, DOMAIN, BaseNotificationService
|
||||
from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService
|
||||
|
||||
from . import CONF_RECIPIENT, DATA_KEY
|
||||
from . import CONF_NOTIFY, CONF_RECIPIENT, DATA_KEY
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -34,7 +34,7 @@ class NetgearNotifyService(BaseNotificationService):
|
|||
_LOGGER.error("Modem not ready")
|
||||
return
|
||||
|
||||
targets = kwargs.get(ATTR_TARGET, self.config[DOMAIN][CONF_RECIPIENT])
|
||||
targets = kwargs.get(ATTR_TARGET, self.config[CONF_NOTIFY][CONF_RECIPIENT])
|
||||
if not targets:
|
||||
_LOGGER.warning("No recipients")
|
||||
return
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
"""Support for Netgear LTE sensors."""
|
||||
from homeassistant.components.sensor import DOMAIN, SensorEntity
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
||||
from . import CONF_MONITORED_CONDITIONS, DATA_KEY, LTEEntity
|
||||
from . import CONF_MONITORED_CONDITIONS, CONF_SENSOR, DATA_KEY, LTEEntity
|
||||
from .sensor_types import SENSOR_SMS, SENSOR_SMS_TOTAL, SENSOR_UNITS, SENSOR_USAGE
|
||||
|
||||
|
||||
|
@ -16,7 +16,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info)
|
|||
if not modem_data or not modem_data.data:
|
||||
raise PlatformNotReady
|
||||
|
||||
sensor_conf = discovery_info[DOMAIN]
|
||||
sensor_conf = discovery_info[CONF_SENSOR]
|
||||
monitored_conditions = sensor_conf[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
sensors = []
|
||||
|
|
Loading…
Reference in New Issue