Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up SMA WebConnect sensor."""
# Check config again during load - dependency available
config = _check_sensor_schema(config)
# Init all default sensors
sensor_def = pysma.Sensors()
# Sensor from the custom config
sensor_def.add(
[
pysma.Sensor(o[CONF_KEY], n, o[CONF_UNIT], o[CONF_FACTOR], o.get(CONF_PATH))
for n, o in config[CONF_CUSTOM].items()
]
)
# Use all sensors by default
config_sensors = config[CONF_SENSORS]
hass_sensors = []
used_sensors = []
if isinstance(config_sensors, dict): # will be remove from 0.99
if not config_sensors: # Use all sensors by default
config_sensors = {s.name: [] for s in sensor_def}
# Prepare all HASS sensor entities
for name, attr in config_sensors.items():
sub_sensors = [sensor_def[s] for s in attr]
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up SMA WebConnect sensor."""
import pysma
# Check config again during load - dependency available
config = _check_sensor_schema(config)
# Init all default sensors
sensor_def = pysma.Sensors()
# Sensor from the custom config
sensor_def.add([pysma.Sensor(o[CONF_KEY], n, o[CONF_UNIT], o[CONF_FACTOR])
for n, o in config[CONF_CUSTOM].items()])
# Use all sensors by default
config_sensors = config[CONF_SENSORS]
if not config_sensors:
config_sensors = {s.name: [] for s in sensor_def}
# Prepare all HASS sensor entities
hass_sensors = []
used_sensors = []
for name, attr in config_sensors.items():
sub_sensors = [sensor_def[s] for s in attr]
hass_sensors.append(SMAsensor(sensor_def[name], sub_sensors))
used_sensors.append(name)
used_sensors.extend(attr)