Example #1
0
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)
Example #2
0
async def test_beta_version_beta_week_pagination(
    aresponses,
    event_loop,
    docker_response_beta_week_page1,
    docker_response_beta_week_page2,
):
    """Test docker beta during beta week."""
    aresponses.add(
        "registry.hub.docker.com",
        "/v2/repositories/homeassistant/home-assistant/tags",
        "get",
        aresponses.Response(
            text=json.dumps(docker_response_beta_week_page1),
            status=200,
            headers=HEADERS,
        ),
    )
    aresponses.add(
        "registry.hub.docker.com",
        "/v2/repositories/homeassistant/home-assistant/tags/page2",
        "get",
        aresponses.Response(
            text=json.dumps(docker_response_beta_week_page2),
            status=200,
            headers=HEADERS,
        ),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        haversion = DockerVersion(event_loop, session, "beta")
        await haversion.get_version()
        assert haversion.version == BETA_VERSION_BETA_WEEK
Example #3
0
async def test():
    """Example usage of pyhaversion."""
    async with aiohttp.ClientSession() as session:
        data = DockerVersion(LOOP, branch="beta", session=session, image="qemux86-64")
        await data.get_version()

        print("Version:", data.version)
        print("Attributes:", data.version_data)
Example #4
0
async def test_stable_version(aresponses, event_loop, docker_response):
    """Test docker stable."""
    aresponses.add(
        "registry.hub.docker.com",
        "/v2/repositories/homeassistant/home-assistant/tags",
        "get",
        aresponses.Response(text=json.dumps(docker_response),
                            status=200,
                            headers=HEADERS),
    )

    async with aiohttp.ClientSession(loop=event_loop) as session:
        haversion = DockerVersion(event_loop, session)
        await haversion.get_version()
        assert haversion.version == STABLE_VERSION