async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """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)
async def test(): """Example usage of pyhaversion.""" async with aiohttp.ClientSession() as session: data = HassioVersion(loop, branch="beta", session=session, image="raspberrypi4") await data.get_version() print("Version:", data.version) print("Attributes:", data.version_data)
async def test_beta_version(aresponses, event_loop, hassio_beta_response): """Test hassio beta.""" aresponses.add( "version.home-assistant.io", "/beta.json", "get", aresponses.Response(text=json.dumps(hassio_beta_response), status=200, headers=HEADERS), ) async with aiohttp.ClientSession(loop=event_loop) as session: haversion = HassioVersion(event_loop, session, "beta") await haversion.get_version() assert haversion.version == BETA_VERSION
async def test_stable_version(aresponses, event_loop, hassio_response): """Test hassio stable.""" aresponses.add( "s3.amazonaws.com", "/hassio-version/stable.json", "get", aresponses.Response(text=json.dumps(hassio_response), status=200, headers=HEADERS), ) async with aiohttp.ClientSession(loop=event_loop) as session: haversion = HassioVersion(event_loop, session) await haversion.get_version() assert haversion.version == STABLE_VERSION
async def test_stable_version_beta_week(aresponses, event_loop, hassio_response_beta_week): """Test hassio stable during beta week.""" aresponses.add( "version.home-assistant.io", "/stable.json", "get", aresponses.Response(text=json.dumps(hassio_response_beta_week), status=200, headers=HEADERS), ) async with aiohttp.ClientSession(loop=event_loop) as session: haversion = HassioVersion(event_loop, session) await haversion.get_version() assert haversion.version == STABLE_VERSION_BETA_WEEK
async def test_beta_version_beta_week(aresponses, event_loop, hassio_beta_response_beta_week): """Test hassio beta during beta week.""" aresponses.add( "s3.amazonaws.com", "/hassio-version/beta.json", "get", aresponses.Response(text=json.dumps(hassio_beta_response_beta_week), status=200, headers=HEADERS), ) async with aiohttp.ClientSession(loop=event_loop) as session: haversion = HassioVersion(event_loop, session, "beta") await haversion.get_version() assert haversion.version == BETA_VERSION_BETA_WEEK