mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
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 config
This commit is contained in:
parent
a1bccb1934
commit
aa062176ca
@ -121,6 +121,28 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
area[CONF_MODE]
|
area[CONF_MODE]
|
||||||
))
|
))
|
||||||
else:
|
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):
|
def _retry(_data):
|
||||||
try:
|
try:
|
||||||
_dev = find_devices(_data)
|
_dev = find_devices(_data)
|
||||||
@ -140,25 +162,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
NETATMO_DEVICE_TYPES[data_class.__name__]
|
NETATMO_DEVICE_TYPES[data_class.__name__]
|
||||||
)
|
)
|
||||||
continue
|
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:
|
try:
|
||||||
dev.extend(find_devices(data))
|
dev.extend(find_devices(data))
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
@ -169,17 +173,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
add_entities(dev, True)
|
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):
|
class NetatmoSensor(Entity):
|
||||||
"""Implementation of a Netatmo sensor."""
|
"""Implementation of a Netatmo sensor."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user