mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Minor updater... updates (#4020)
* Enable updater in dev versions * Code clarity * Add log line about being on the current version already * Remove dev check test
This commit is contained in:
parent
519d9f2fd0
commit
0c563f7b14
@ -61,8 +61,9 @@ def setup(hass, config):
|
|||||||
"""Setup the updater component."""
|
"""Setup the updater component."""
|
||||||
if 'dev' in CURRENT_VERSION:
|
if 'dev' in CURRENT_VERSION:
|
||||||
# This component only makes sense in release versions
|
# This component only makes sense in release versions
|
||||||
_LOGGER.warning('Updater not supported in development version')
|
_LOGGER.warning(('Updater component enabled in dev. '
|
||||||
return False
|
'You will not receive notifications of new '
|
||||||
|
'versions but analytics will be submitted.'))
|
||||||
|
|
||||||
config = config.get(DOMAIN, {})
|
config = config.get(DOMAIN, {})
|
||||||
huuid = _load_uuid(hass) if config.get(CONF_REPORTING) else None
|
huuid = _load_uuid(hass) if config.get(CONF_REPORTING) else None
|
||||||
@ -80,12 +81,18 @@ def check_newest_version(hass, huuid):
|
|||||||
"""Check if a new version is available and report if one is."""
|
"""Check if a new version is available and report if one is."""
|
||||||
newest, releasenotes = get_newest_version(huuid)
|
newest, releasenotes = get_newest_version(huuid)
|
||||||
|
|
||||||
if newest is not None:
|
if newest is None or 'dev' in CURRENT_VERSION:
|
||||||
if StrictVersion(newest) > StrictVersion(CURRENT_VERSION):
|
return
|
||||||
hass.states.set(
|
|
||||||
ENTITY_ID, newest, {ATTR_FRIENDLY_NAME: 'Update Available',
|
if StrictVersion(newest) > StrictVersion(CURRENT_VERSION):
|
||||||
ATTR_RELEASE_NOTES: releasenotes}
|
_LOGGER.info('The latest available version is %s.', newest)
|
||||||
)
|
hass.states.set(
|
||||||
|
ENTITY_ID, newest, {ATTR_FRIENDLY_NAME: 'Update Available',
|
||||||
|
ATTR_RELEASE_NOTES: releasenotes}
|
||||||
|
)
|
||||||
|
elif StrictVersion(newest) == StrictVersion(CURRENT_VERSION):
|
||||||
|
_LOGGER.info('You are on the latest version (%s) of Home Assistant.',
|
||||||
|
newest)
|
||||||
|
|
||||||
|
|
||||||
def get_newest_version(huuid):
|
def get_newest_version(huuid):
|
||||||
@ -95,7 +102,7 @@ def get_newest_version(huuid):
|
|||||||
'os_name': platform.system(), "arch": platform.machine(),
|
'os_name': platform.system(), "arch": platform.machine(),
|
||||||
'python_version': platform.python_version(),
|
'python_version': platform.python_version(),
|
||||||
'virtualenv': (os.environ.get('VIRTUAL_ENV') is not None),
|
'virtualenv': (os.environ.get('VIRTUAL_ENV') is not None),
|
||||||
'docker': False}
|
'docker': False, 'dev': ('dev' in CURRENT_VERSION)}
|
||||||
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
info_object['os_version'] = platform.win32_ver()[0]
|
info_object['os_version'] = platform.win32_ver()[0]
|
||||||
@ -114,9 +121,8 @@ def get_newest_version(huuid):
|
|||||||
try:
|
try:
|
||||||
req = requests.post(UPDATER_URL, json=info_object)
|
req = requests.post(UPDATER_URL, json=info_object)
|
||||||
res = req.json()
|
res = req.json()
|
||||||
_LOGGER.info(('The latest version is %s. '
|
_LOGGER.info(('Submitted analytics to Home Assistant servers. '
|
||||||
'Information submitted includes %s'),
|
'Information submitted includes %s'), info_object)
|
||||||
res['version'], info_object)
|
|
||||||
return (res['version'], res['release-notes'])
|
return (res['version'], res['release-notes'])
|
||||||
except requests.RequestException:
|
except requests.RequestException:
|
||||||
_LOGGER.exception('Could not contact HASS Update to check for updates')
|
_LOGGER.exception('Could not contact HASS Update to check for updates')
|
||||||
|
@ -89,15 +89,6 @@ class TestUpdater(unittest.TestCase):
|
|||||||
mock_get.side_effect = KeyError
|
mock_get.side_effect = KeyError
|
||||||
self.assertIsNone(updater.get_newest_version(uuid))
|
self.assertIsNone(updater.get_newest_version(uuid))
|
||||||
|
|
||||||
def test_updater_disabled_on_dev(self):
|
|
||||||
"""Test if the updater component is disabled on dev."""
|
|
||||||
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev'
|
|
||||||
|
|
||||||
with assert_setup_component(1) as config:
|
|
||||||
assert not setup_component(
|
|
||||||
self.hass, updater.DOMAIN, {updater.DOMAIN: {}})
|
|
||||||
assert config['updater'] == {'reporting': True}
|
|
||||||
|
|
||||||
def test_uuid_function(self):
|
def test_uuid_function(self):
|
||||||
"""Test if the uuid function works."""
|
"""Test if the uuid function works."""
|
||||||
path = self.hass.config.path(updater.UPDATER_UUID_FILE)
|
path = self.hass.config.path(updater.UPDATER_UUID_FILE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user