Clean up Netatmo sensor code (#25390)
* Clean up code * Add parameter * Make it a list * Move loop and add debug message * Further clean up * Move manual configpull/25450/head
parent
a1bccb1934
commit
aa062176ca
|
@ -121,6 +121,28 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
area[CONF_MODE]
|
||||
))
|
||||
else:
|
||||
def find_devices(data):
|
||||
"""Find all devices."""
|
||||
all_module_names = data.get_module_names()
|
||||
module_names = config.get(CONF_MODULES, all_module_names)
|
||||
_dev = []
|
||||
for module_name in module_names:
|
||||
if module_name not in all_module_names:
|
||||
_LOGGER.info("Module %s not found", module_name)
|
||||
continue
|
||||
for condition in \
|
||||
data.station_data.monitoredConditions(module_name):
|
||||
_LOGGER.debug(
|
||||
"Adding %s %s",
|
||||
module_name,
|
||||
data.station_data.moduleByName(
|
||||
station=data.station, module=module_name
|
||||
)
|
||||
)
|
||||
_dev.append(NetatmoSensor(
|
||||
data, module_name, condition.lower(), data.station))
|
||||
return _dev
|
||||
|
||||
def _retry(_data):
|
||||
try:
|
||||
_dev = find_devices(_data)
|
||||
|
@ -140,25 +162,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
NETATMO_DEVICE_TYPES[data_class.__name__]
|
||||
)
|
||||
continue
|
||||
# Test if manually configured
|
||||
if CONF_MODULES in config:
|
||||
module_items = config[CONF_MODULES]
|
||||
for module_name in module_items:
|
||||
if module_name not in data.get_module_names():
|
||||
continue
|
||||
for condition in data.station_data.monitoredConditions(
|
||||
module_name):
|
||||
dev.append(
|
||||
NetatmoSensor(
|
||||
data,
|
||||
module_name,
|
||||
condition.lower(),
|
||||
data.station
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
# otherwise add all modules and conditions
|
||||
try:
|
||||
dev.extend(find_devices(data))
|
||||
except requests.exceptions.Timeout:
|
||||
|
@ -169,17 +173,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
add_entities(dev, True)
|
||||
|
||||
|
||||
def find_devices(data):
|
||||
"""Find all devices."""
|
||||
dev = []
|
||||
module_names = data.get_module_names()
|
||||
for module_name in module_names:
|
||||
for condition in data.station_data.monitoredConditions(module_name):
|
||||
dev.append(NetatmoSensor(
|
||||
data, module_name, condition.lower(), data.station))
|
||||
return dev
|
||||
|
||||
|
||||
class NetatmoSensor(Entity):
|
||||
"""Implementation of a Netatmo sensor."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue