コード例 #1
0
ファイル: sensor.py プロジェクト: ddub/home-assstant-core
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)
コード例 #2
0
ファイル: example.py プロジェクト: frenck/pyhaversion
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)
コード例 #3
0
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
コード例 #4
0
ファイル: test_hassio.py プロジェクト: pvizeli/pyhaversion
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
コード例 #5
0
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
コード例 #6
0
ファイル: test_hassio.py プロジェクト: pvizeli/pyhaversion
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