From 4d8ef115a3b552c6acff3e786c6d73aabf481c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 31 Mar 2021 12:46:14 +0200 Subject: [PATCH] Bump pyhaversion from 3.4.2 to 21.3.0 (#48537) --- .../components/version/manifest.json | 2 +- homeassistant/components/version/sensor.py | 107 ++++++++++-------- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/homeassistant/components/version/manifest.json b/homeassistant/components/version/manifest.json index 7fc1a097d81..7f55273383d 100644 --- a/homeassistant/components/version/manifest.json +++ b/homeassistant/components/version/manifest.json @@ -2,7 +2,7 @@ "domain": "version", "name": "Version", "documentation": "https://www.home-assistant.io/integrations/version", - "requirements": ["pyhaversion==3.4.2"], + "requirements": ["pyhaversion==21.3.0"], "codeowners": ["@fabaff", "@ludeeus"], "quality_scale": "internal" } diff --git a/homeassistant/components/version/sensor.py b/homeassistant/components/version/sensor.py index 3e5d235b5d7..9d558f4ba7c 100644 --- a/homeassistant/components/version/sensor.py +++ b/homeassistant/components/version/sensor.py @@ -1,13 +1,7 @@ """Sensor that can display the current Home Assistant versions.""" from datetime import timedelta -from pyhaversion import ( - DockerVersion, - HaIoVersion, - HassioVersion, - LocalVersion, - PyPiVersion, -) +from pyhaversion import HaVersion, HaVersionChannel, HaVersionSource import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity @@ -19,22 +13,30 @@ from homeassistant.util import Throttle ALL_IMAGES = [ "default", "intel-nuc", - "qemux86", - "qemux86-64", - "qemuarm", - "qemuarm-64", - "raspberrypi", - "raspberrypi2", - "raspberrypi3", - "raspberrypi3-64", - "raspberrypi4", - "raspberrypi4-64", - "tinker", "odroid-c2", "odroid-n2", "odroid-xu", + "qemuarm-64", + "qemuarm", + "qemux86-64", + "qemux86", + "raspberrypi", + "raspberrypi2", + "raspberrypi3-64", + "raspberrypi3", + "raspberrypi4-64", + "raspberrypi4", + "tinker", +] +ALL_SOURCES = [ + "container", + "haio", + "local", + "pypi", + "supervisor", + "hassio", # Kept to not break existing configurations + "docker", # Kept to not break existing configurations ] -ALL_SOURCES = ["local", "pypi", "hassio", "docker", "haio"] CONF_BETA = "beta" CONF_IMAGE = "image" @@ -68,21 +70,30 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= session = async_get_clientsession(hass) - if beta: - branch = "beta" - else: - branch = "stable" + channel = HaVersionChannel.BETA if beta else HaVersionChannel.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)) + haversion = VersionData( + HaVersion(session, source=HaVersionSource.PYPI, channel=channel) + ) + elif source in ["hassio", "supervisor"]: + haversion = VersionData( + HaVersion( + session, source=HaVersionSource.SUPERVISOR, channel=channel, image=image + ) + ) + elif source in ["docker", "container"]: + if image is not None and image != DEFAULT_IMAGE: + image = f"{image}-homeassistant" + haversion = VersionData( + HaVersion( + session, source=HaVersionSource.CONTAINER, channel=channel, image=image + ) + ) elif source == "haio": - haversion = VersionData(HaIoVersion(hass.loop, session)) + haversion = VersionData(HaVersion(session, source=HaVersionSource.HAIO)) else: - haversion = VersionData(LocalVersion(hass.loop, session)) + haversion = VersionData(HaVersion(session, source=HaVersionSource.LOCAL)) if not name: if source == DEFAULT_SOURCE: @@ -93,18 +104,31 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async_add_entities([VersionSensor(haversion, name)], True) +class VersionData: + """Get the latest data and update the states.""" + + def __init__(self, api: HaVersion): + """Initialize the data object.""" + self.api = api + + @Throttle(TIME_BETWEEN_UPDATES) + async def async_update(self): + """Get the latest version information.""" + await self.api.get_version() + + class VersionSensor(SensorEntity): """Representation of a Home Assistant version sensor.""" - def __init__(self, haversion, name): + def __init__(self, data: VersionData, name: str): """Initialize the Version sensor.""" - self.haversion = haversion + self.data = data self._name = name self._state = None async def async_update(self): """Get the latest version information.""" - await self.haversion.async_update() + await self.data.async_update() @property def name(self): @@ -114,27 +138,14 @@ class VersionSensor(SensorEntity): @property def state(self): """Return the state of the sensor.""" - return self.haversion.api.version + return self.data.api.version @property def extra_state_attributes(self): """Return attributes for the sensor.""" - return self.haversion.api.version_data + return self.data.api.version_data @property def icon(self): """Return the icon to use in the frontend, if any.""" return ICON - - -class VersionData: - """Get the latest data and update the states.""" - - def __init__(self, api): - """Initialize the data object.""" - self.api = api - - @Throttle(TIME_BETWEEN_UPDATES) - async def async_update(self): - """Get the latest version information.""" - await self.api.get_version() diff --git a/requirements_all.txt b/requirements_all.txt index 999d9f618c9..d91f9f31865 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1422,7 +1422,7 @@ pygtfs==0.1.5 pygti==0.9.2 # homeassistant.components.version -pyhaversion==3.4.2 +pyhaversion==21.3.0 # homeassistant.components.heos pyheos==0.7.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 50496876386..8ba4028fe6b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -748,7 +748,7 @@ pygatt[GATTTOOL]==4.0.5 pygti==0.9.2 # homeassistant.components.version -pyhaversion==3.4.2 +pyhaversion==21.3.0 # homeassistant.components.heos pyheos==0.7.2