Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
async_add_entities(hass_sensors)
used_sensors = [sensor_def[s] for s in set(used_sensors)]
# Init the SMA interface
session = async_get_clientsession(hass, verify_ssl=config[CONF_VERIFY_SSL])
grp = config[CONF_GROUP]
url = "http{}://{}".format(
"s" if config[CONF_SSL] else "", config[CONF_HOST])
sma = pysma.SMA(session, url, config[CONF_PASSWORD], group=grp)
# Ensure we logout on shutdown
async def async_close_session(event):
"""Close the session."""
await sma.close_session()
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, async_close_session)
backoff = 0
backoff_step = 0
async def async_sma(event):
"""Update all the SMA sensors."""
nonlocal backoff, backoff_step
if backoff > 1:
backoff -= 1
if not config_sensors: # Use all sensors by default
config_sensors = [s.name for s in sensor_def]
used_sensors = list(set(config_sensors + list(config[CONF_CUSTOM].keys())))
for sensor in used_sensors:
hass_sensors.append(SMAsensor(sensor_def[sensor], []))
used_sensors = [sensor_def[s] for s in set(used_sensors)]
async_add_entities(hass_sensors)
# Init the SMA interface
session = async_get_clientsession(hass, verify_ssl=config[CONF_VERIFY_SSL])
grp = config[CONF_GROUP]
url = "http{}://{}".format("s" if config[CONF_SSL] else "", config[CONF_HOST])
sma = pysma.SMA(session, url, config[CONF_PASSWORD], group=grp)
# Ensure we logout on shutdown
async def async_close_session(event):
"""Close the session."""
await sma.close_session()
hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, async_close_session)
backoff = 0
backoff_step = 0
async def async_sma(event):
"""Update all the SMA sensors."""
nonlocal backoff, backoff_step
if backoff > 1:
backoff -= 1