Bump pyhaversion from 3.4.2 to 21.3.0 (#48537)

This commit is contained in:
Joakim Sørensen 2021-03-31 12:46:14 +02:00 committed by GitHub
parent 96857b7466
commit 4d8ef115a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 51 deletions

View file

@ -2,7 +2,7 @@
"domain": "version", "domain": "version",
"name": "Version", "name": "Version",
"documentation": "https://www.home-assistant.io/integrations/version", "documentation": "https://www.home-assistant.io/integrations/version",
"requirements": ["pyhaversion==3.4.2"], "requirements": ["pyhaversion==21.3.0"],
"codeowners": ["@fabaff", "@ludeeus"], "codeowners": ["@fabaff", "@ludeeus"],
"quality_scale": "internal" "quality_scale": "internal"
} }

View file

@ -1,13 +1,7 @@
"""Sensor that can display the current Home Assistant versions.""" """Sensor that can display the current Home Assistant versions."""
from datetime import timedelta from datetime import timedelta
from pyhaversion import ( from pyhaversion import HaVersion, HaVersionChannel, HaVersionSource
DockerVersion,
HaIoVersion,
HassioVersion,
LocalVersion,
PyPiVersion,
)
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
@ -19,22 +13,30 @@ from homeassistant.util import Throttle
ALL_IMAGES = [ ALL_IMAGES = [
"default", "default",
"intel-nuc", "intel-nuc",
"qemux86",
"qemux86-64",
"qemuarm",
"qemuarm-64",
"raspberrypi",
"raspberrypi2",
"raspberrypi3",
"raspberrypi3-64",
"raspberrypi4",
"raspberrypi4-64",
"tinker",
"odroid-c2", "odroid-c2",
"odroid-n2", "odroid-n2",
"odroid-xu", "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_BETA = "beta"
CONF_IMAGE = "image" CONF_IMAGE = "image"
@ -68,21 +70,30 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
session = async_get_clientsession(hass) session = async_get_clientsession(hass)
if beta: channel = HaVersionChannel.BETA if beta else HaVersionChannel.STABLE
branch = "beta"
else:
branch = "stable"
if source == "pypi": if source == "pypi":
haversion = VersionData(PyPiVersion(hass.loop, session, branch)) haversion = VersionData(
elif source == "hassio": HaVersion(session, source=HaVersionSource.PYPI, channel=channel)
haversion = VersionData(HassioVersion(hass.loop, session, branch, image)) )
elif source == "docker": elif source in ["hassio", "supervisor"]:
haversion = VersionData(DockerVersion(hass.loop, session, branch, image)) 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": elif source == "haio":
haversion = VersionData(HaIoVersion(hass.loop, session)) haversion = VersionData(HaVersion(session, source=HaVersionSource.HAIO))
else: else:
haversion = VersionData(LocalVersion(hass.loop, session)) haversion = VersionData(HaVersion(session, source=HaVersionSource.LOCAL))
if not name: if not name:
if source == DEFAULT_SOURCE: 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) 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): class VersionSensor(SensorEntity):
"""Representation of a Home Assistant version sensor.""" """Representation of a Home Assistant version sensor."""
def __init__(self, haversion, name): def __init__(self, data: VersionData, name: str):
"""Initialize the Version sensor.""" """Initialize the Version sensor."""
self.haversion = haversion self.data = data
self._name = name self._name = name
self._state = None self._state = None
async def async_update(self): async def async_update(self):
"""Get the latest version information.""" """Get the latest version information."""
await self.haversion.async_update() await self.data.async_update()
@property @property
def name(self): def name(self):
@ -114,27 +138,14 @@ class VersionSensor(SensorEntity):
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.haversion.api.version return self.data.api.version
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return attributes for the sensor.""" """Return attributes for the sensor."""
return self.haversion.api.version_data return self.data.api.version_data
@property @property
def icon(self): def icon(self):
"""Return the icon to use in the frontend, if any.""" """Return the icon to use in the frontend, if any."""
return ICON 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()

View file

@ -1422,7 +1422,7 @@ pygtfs==0.1.5
pygti==0.9.2 pygti==0.9.2
# homeassistant.components.version # homeassistant.components.version
pyhaversion==3.4.2 pyhaversion==21.3.0
# homeassistant.components.heos # homeassistant.components.heos
pyheos==0.7.2 pyheos==0.7.2

View file

@ -748,7 +748,7 @@ pygatt[GATTTOOL]==4.0.5
pygti==0.9.2 pygti==0.9.2
# homeassistant.components.version # homeassistant.components.version
pyhaversion==3.4.2 pyhaversion==21.3.0
# homeassistant.components.heos # homeassistant.components.heos
pyheos==0.7.2 pyheos==0.7.2