Bump pyhaversion from 3.4.2 to 21.3.0 (#48537)
This commit is contained in:
parent
96857b7466
commit
4d8ef115a3
4 changed files with 62 additions and 51 deletions
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue