mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Fix updater, add new fields (#3982)
* Fix updater * Add Docker and virtualenv checks * Add log line informing user of update/analytics * Remove str
This commit is contained in:
parent
ea91d24eb2
commit
ca6fa1313e
@ -9,6 +9,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import platform
|
import platform
|
||||||
import uuid
|
import uuid
|
||||||
|
import os
|
||||||
# pylint: disable=no-name-in-module,import-error
|
# pylint: disable=no-name-in-module,import-error
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ def setup(hass, config):
|
|||||||
_LOGGER.warning('Updater not supported in development version')
|
_LOGGER.warning('Updater not supported in development version')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
# Update daily, start 1 hour after startup
|
# Update daily, start 1 hour after startup
|
||||||
@ -91,7 +93,9 @@ def get_newest_version(huuid):
|
|||||||
info_object = {'uuid': huuid, 'version': CURRENT_VERSION,
|
info_object = {'uuid': huuid, 'version': CURRENT_VERSION,
|
||||||
'timezone': dt_util.DEFAULT_TIME_ZONE.zone,
|
'timezone': dt_util.DEFAULT_TIME_ZONE.zone,
|
||||||
'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),
|
||||||
|
'docker': False}
|
||||||
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
info_object['os_version'] = platform.win32_ver()[0]
|
info_object['os_version'] = platform.win32_ver()[0]
|
||||||
@ -102,6 +106,7 @@ def get_newest_version(huuid):
|
|||||||
linux_dist = distro.linux_distribution(full_distribution_name=False)
|
linux_dist = distro.linux_distribution(full_distribution_name=False)
|
||||||
info_object['distribution'] = linux_dist[0]
|
info_object['distribution'] = linux_dist[0]
|
||||||
info_object['os_version'] = linux_dist[1]
|
info_object['os_version'] = linux_dist[1]
|
||||||
|
info_object['docker'] = os.path.isfile('/.dockerenv')
|
||||||
|
|
||||||
if not huuid:
|
if not huuid:
|
||||||
info_object = {}
|
info_object = {}
|
||||||
@ -109,6 +114,9 @@ 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. '
|
||||||
|
'Information submitted includes %s'),
|
||||||
|
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')
|
||||||
|
@ -5,6 +5,7 @@ from unittest.mock import patch
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import requests_mock
|
||||||
|
|
||||||
from homeassistant.bootstrap import setup_component
|
from homeassistant.bootstrap import setup_component
|
||||||
from homeassistant.components import updater
|
from homeassistant.components import updater
|
||||||
@ -111,3 +112,19 @@ class TestUpdater(unittest.TestCase):
|
|||||||
assert uuid != uuid2
|
assert uuid != uuid2
|
||||||
finally:
|
finally:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
|
@requests_mock.Mocker()
|
||||||
|
def test_reporting_false_works(self, m):
|
||||||
|
"""Test we do not send any data."""
|
||||||
|
m.post(updater.UPDATER_URL,
|
||||||
|
json={'version': '0.15',
|
||||||
|
'release-notes': 'https://home-assistant.io'})
|
||||||
|
|
||||||
|
response = updater.get_newest_version(None)
|
||||||
|
|
||||||
|
assert response == ('0.15', 'https://home-assistant.io')
|
||||||
|
|
||||||
|
history = m.request_history
|
||||||
|
|
||||||
|
assert len(history) == 1
|
||||||
|
assert history[0].json() == {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user