mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Version sensor update (#25162)
* component -> integration * Bump pyhaversion to 3.0.2 * Update requirements * Formating
This commit is contained in:
parent
99c6c60bec
commit
50f9117982
@ -1 +1 @@
|
|||||||
"""The version component."""
|
"""The version integration."""
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Version",
|
"name": "Version",
|
||||||
"documentation": "https://www.home-assistant.io/components/version",
|
"documentation": "https://www.home-assistant.io/components/version",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyhaversion==2.2.1"
|
"pyhaversion==3.0.2"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
|
@ -45,18 +45,38 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass, config, async_add_entities, discovery_info=None):
|
hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up the Version sensor platform."""
|
"""Set up the Version sensor platform."""
|
||||||
from pyhaversion import Version
|
from pyhaversion import (
|
||||||
|
LocalVersion, DockerVersion, HassioVersion, PyPiVersion)
|
||||||
beta = config.get(CONF_BETA)
|
beta = config.get(CONF_BETA)
|
||||||
image = config.get(CONF_IMAGE)
|
image = config.get(CONF_IMAGE)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
source = config.get(CONF_SOURCE)
|
source = config.get(CONF_SOURCE)
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
|
|
||||||
if beta:
|
if beta:
|
||||||
branch = 'beta'
|
branch = 'beta'
|
||||||
else:
|
else:
|
||||||
branch = 'stable'
|
branch = 'stable'
|
||||||
haversion = VersionData(Version(hass.loop, session, branch, image), source)
|
|
||||||
|
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))
|
||||||
|
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)
|
async_add_entities([VersionSensor(haversion, name)], True)
|
||||||
|
|
||||||
@ -64,7 +84,7 @@ async def async_setup_platform(
|
|||||||
class VersionSensor(Entity):
|
class VersionSensor(Entity):
|
||||||
"""Representation of a Home Assistant version sensor."""
|
"""Representation of a Home Assistant version sensor."""
|
||||||
|
|
||||||
def __init__(self, haversion, name=''):
|
def __init__(self, haversion, name):
|
||||||
"""Initialize the Version sensor."""
|
"""Initialize the Version sensor."""
|
||||||
self.haversion = haversion
|
self.haversion = haversion
|
||||||
self._name = name
|
self._name = name
|
||||||
@ -77,11 +97,7 @@ class VersionSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
if self._name:
|
|
||||||
return self._name
|
return self._name
|
||||||
if self.haversion.source == DEFAULT_SOURCE:
|
|
||||||
return DEFAULT_NAME_LOCAL
|
|
||||||
return DEFAULT_NAME_LATEST
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -102,19 +118,11 @@ class VersionSensor(Entity):
|
|||||||
class VersionData:
|
class VersionData:
|
||||||
"""Get the latest data and update the states."""
|
"""Get the latest data and update the states."""
|
||||||
|
|
||||||
def __init__(self, api, source):
|
def __init__(self, api):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.api = api
|
self.api = api
|
||||||
self.source = source
|
|
||||||
|
|
||||||
@Throttle(TIME_BETWEEN_UPDATES)
|
@Throttle(TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest version information."""
|
"""Get the latest version information."""
|
||||||
if self.source == 'pypi':
|
await self.api.get_version()
|
||||||
await self.api.get_pypi_version()
|
|
||||||
elif self.source == 'hassio':
|
|
||||||
await self.api.get_hassio_version()
|
|
||||||
elif self.source == 'docker':
|
|
||||||
await self.api.get_docker_version()
|
|
||||||
else:
|
|
||||||
await self.api.get_local_version()
|
|
||||||
|
@ -1160,7 +1160,7 @@ pygtfs==0.1.5
|
|||||||
pygtt==1.1.2
|
pygtt==1.1.2
|
||||||
|
|
||||||
# homeassistant.components.version
|
# homeassistant.components.version
|
||||||
pyhaversion==2.2.1
|
pyhaversion==3.0.2
|
||||||
|
|
||||||
# homeassistant.components.heos
|
# homeassistant.components.heos
|
||||||
pyheos==0.5.2
|
pyheos==0.5.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user