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 update_data(hass, throttle):
"""Update data."""
if throttle.throttle:
return
throttle.set_last_run()
if len(hass.data[DOMAIN_DATA]["components"]) == 1:
return
from pyhaversion import LocalVersion, PyPiVersion
session = async_get_clientsession(hass)
webclient = WebClient(session)
localversion = LocalVersion(hass.loop, session)
pypiversion = PyPiVersion(hass.loop, session)
try:
await localversion.get_version()
currentversion = localversion.version.split(".")[1]
await pypiversion.get_version()
remoteversion = pypiversion.version.split(".")[1]
except Exception: # pylint: disable=broad-except
_LOGGER.warning("Could not get version data.")
return
if currentversion == remoteversion:
_LOGGER.debug(
"Current version is %s and remote version is %s skipping update",
currentversion,
remoteversion,
async def update_data(hass, throttle):
"""Update data."""
if throttle.throttle:
return
throttle.set_last_run()
if len(hass.data[DOMAIN_DATA]["components"]) == 1:
return
from pyhaversion import LocalVersion, PyPiVersion
session = async_get_clientsession(hass)
webclient = WebClient(session)
localversion = LocalVersion(hass.loop, session)
pypiversion = PyPiVersion(hass.loop, session)
try:
await localversion.get_version()
currentversion = localversion.version.split(".")[1]
await pypiversion.get_version()
remoteversion = pypiversion.version.split(".")[1]
except Exception: # pylint: disable=broad-except
_LOGGER.warning("Could not get version data.")
return
if currentversion == remoteversion:
_LOGGER.debug(
"Current version is %s and remote version is %s skipping update",
currentversion,
remoteversion,
"""Set up the Version sensor platform."""
beta = config.get(CONF_BETA)
image = config.get(CONF_IMAGE)
name = config.get(CONF_NAME)
source = config.get(CONF_SOURCE)
session = async_get_clientsession(hass)
if beta:
branch = "beta"
else:
branch = "stable"
if source == "pypi":
haversion = VersionData(PyPiVersion(hass.loop, session, branch))
elif source == "hassio":
haversion = VersionData(HassioVersion(hass.loop, session, branch, image))
elif source == "docker":
haversion = VersionData(DockerVersion(hass.loop, session, branch, image))
elif source == "haio":
haversion = VersionData(HaIoVersion(hass.loop, session))
else:
haversion = VersionData(LocalVersion(hass.loop, session))
if not name:
if source == DEFAULT_SOURCE:
name = DEFAULT_NAME_LOCAL
else:
name = DEFAULT_NAME_LATEST
async_add_entities([VersionSensor(haversion, name)], True)