Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate the netgear_lte configuration #22105

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions homeassistant/components/netgear_lte/__init__.py
Expand Up @@ -17,6 +17,8 @@
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.util import Throttle

from . import sensor_types

REQUIREMENTS = ['eternalegypt==0.0.5']

_LOGGER = logging.getLogger(__name__)
Expand All @@ -35,16 +37,21 @@

SENSOR_SCHEMA = vol.Schema({
vol.Required(CONF_MONITORED_CONDITIONS):
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
vol.All(cv.ensure_list, [cv.string]),
vol.All(cv.ensure_list, [vol.In(sensor_types.ALL_SENSORS)]),
})

DEFAULT_SENSOR = {
amelchio marked this conversation as resolved.
Show resolved Hide resolved
CONF_MONITORED_CONDITIONS: sensor_types.DEFAULT_SENSORS
}

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.All(cv.ensure_list, [vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(NOTIFY_DOMAIN, default={}):
vol.All(cv.ensure_list, [NOTIFY_SCHEMA]),
vol.Optional(SENSOR_DOMAIN): SENSOR_SCHEMA,
vol.Optional(SENSOR_DOMAIN, default=DEFAULT_SENSOR):
amelchio marked this conversation as resolved.
Show resolved Hide resolved
SENSOR_SCHEMA,
})])
}, extra=vol.ALLOW_EXTRA)

Expand Down
13 changes: 2 additions & 11 deletions homeassistant/components/netgear_lte/sensor.py
Expand Up @@ -8,16 +8,12 @@
from homeassistant.helpers.entity import Entity

from . import CONF_MONITORED_CONDITIONS, DATA_KEY
from .sensor_types import SENSOR_SMS, SENSOR_USAGE

DEPENDENCIES = ['netgear_lte']

_LOGGER = logging.getLogger(__name__)

SENSOR_SMS = 'sms'
SENSOR_USAGE = 'usage'

DEFAULT_SENSORS = [SENSOR_SMS, SENSOR_USAGE]


async def async_setup_platform(
hass, config, async_add_entities, discovery_info):
Expand All @@ -31,19 +27,14 @@ async def async_setup_platform(
raise PlatformNotReady

sensor_conf = discovery_info[DOMAIN]
if sensor_conf:
monitored_conditions = sensor_conf[CONF_MONITORED_CONDITIONS]
else:
monitored_conditions = DEFAULT_SENSORS
monitored_conditions = sensor_conf[CONF_MONITORED_CONDITIONS]

sensors = []
for sensor_type in monitored_conditions:
if sensor_type == SENSOR_SMS:
sensors.append(SMSSensor(modem_data, sensor_type))
elif sensor_type == SENSOR_USAGE:
sensors.append(UsageSensor(modem_data, sensor_type))
else:
_LOGGER.error("Unknown sensor type '%s'", sensor_type)

async_add_entities(sensors, True)

Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/netgear_lte/sensor_types.py
@@ -0,0 +1,8 @@
"""Define possible sensor types."""

SENSOR_SMS = 'sms'
SENSOR_USAGE = 'usage'

ALL_SENSORS = [SENSOR_SMS, SENSOR_USAGE]

DEFAULT_SENSORS = [SENSOR_USAGE]