Updater improvements to send option component information (#7720)
* Setup to send component data is option is enabled * testcases, as well as moved to a single boolean, passed to the function * fixed pep8 failures * Clarify config option.
This commit is contained in:
parent
a119bd0056
commit
437ddb8dea
2 changed files with 40 additions and 10 deletions
|
@ -32,6 +32,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
ATTR_RELEASE_NOTES = 'release_notes'
|
||||
|
||||
CONF_REPORTING = 'reporting'
|
||||
CONF_COMPONENT_REPORTING = 'include_used_components'
|
||||
|
||||
DOMAIN = 'updater'
|
||||
|
||||
|
@ -41,7 +42,8 @@ UPDATER_URL = 'https://updater.home-assistant.io/'
|
|||
UPDATER_UUID_FILE = '.uuid'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({DOMAIN: {
|
||||
vol.Optional(CONF_REPORTING, default=True): cv.boolean
|
||||
vol.Optional(CONF_REPORTING, default=True): cv.boolean,
|
||||
vol.Optional(CONF_COMPONENT_REPORTING, default=False): cv.boolean,
|
||||
}}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
RESPONSE_SCHEMA = vol.Schema({
|
||||
|
@ -83,10 +85,13 @@ def async_setup(hass, config):
|
|||
else:
|
||||
huuid = None
|
||||
|
||||
include_components = config.get(CONF_COMPONENT_REPORTING)
|
||||
|
||||
@asyncio.coroutine
|
||||
def check_new_version(now):
|
||||
"""Check if a new version is available and report if one is."""
|
||||
result = yield from get_newest_version(hass, huuid)
|
||||
result = yield from get_newest_version(hass, huuid,
|
||||
include_components)
|
||||
|
||||
if result is None:
|
||||
return
|
||||
|
@ -116,7 +121,7 @@ def async_setup(hass, config):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def get_system_info(hass):
|
||||
def get_system_info(hass, include_components):
|
||||
"""Return info about the system."""
|
||||
info_object = {
|
||||
'arch': platform.machine(),
|
||||
|
@ -129,6 +134,9 @@ def get_system_info(hass):
|
|||
'virtualenv': os.environ.get('VIRTUAL_ENV') is not None,
|
||||
}
|
||||
|
||||
if include_components:
|
||||
info_object['components'] = list(hass.config.components)
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
info_object['os_version'] = platform.win32_ver()[0]
|
||||
elif platform.system() == 'Darwin':
|
||||
|
@ -147,10 +155,10 @@ def get_system_info(hass):
|
|||
|
||||
|
||||
@asyncio.coroutine
|
||||
def get_newest_version(hass, huuid):
|
||||
def get_newest_version(hass, huuid, include_components):
|
||||
"""Get the newest Home Assistant version."""
|
||||
if huuid:
|
||||
info_object = yield from get_system_info(hass)
|
||||
info_object = yield from get_system_info(hass, include_components)
|
||||
info_object['huuid'] = huuid
|
||||
else:
|
||||
info_object = {}
|
||||
|
|
|
@ -19,6 +19,9 @@ MOCK_RESPONSE = {
|
|||
'version': '0.15',
|
||||
'release-notes': 'https://home-assistant.io'
|
||||
}
|
||||
MOCK_CONFIG = {updater.DOMAIN: {
|
||||
'reporting': True
|
||||
}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -94,11 +97,30 @@ def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version):
|
|||
yield from hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(updater.ENTITY_ID) is None
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, MOCK_CONFIG)
|
||||
call = mock_get_newest_version.mock_calls[0][1]
|
||||
assert call[0] is hass
|
||||
assert call[1] is None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_enabled_component_info(hass, mock_get_uuid):
|
||||
"""Test if new entity is created if new version is available."""
|
||||
with patch('homeassistant.components.updater.platform.system',
|
||||
Mock(return_value="junk")):
|
||||
res = yield from updater.get_system_info(hass, True)
|
||||
assert 'components' in res, 'Updater failed to generate component list'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_disable_component_info(hass, mock_get_uuid):
|
||||
"""Test if new entity is created if new version is available."""
|
||||
with patch('homeassistant.components.updater.platform.system',
|
||||
Mock(return_value="junk")):
|
||||
res = yield from updater.get_system_info(hass, False)
|
||||
assert 'components' not in res, 'Updater failed, components generate'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
|
||||
"""Test we do not gather analytics when no huuid is passed in."""
|
||||
|
@ -106,7 +128,7 @@ def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
side_effect=Exception):
|
||||
res = yield from updater.get_newest_version(hass, None)
|
||||
res = yield from updater.get_newest_version(hass, None, False)
|
||||
assert res == (MOCK_RESPONSE['version'],
|
||||
MOCK_RESPONSE['release-notes'])
|
||||
|
||||
|
@ -118,7 +140,7 @@ def test_get_newest_version_analytics_when_huuid(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res == (MOCK_RESPONSE['version'],
|
||||
MOCK_RESPONSE['release-notes'])
|
||||
|
||||
|
@ -129,7 +151,7 @@ def test_error_fetching_new_version_timeout(hass):
|
|||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))), \
|
||||
patch('async_timeout.timeout', side_effect=asyncio.TimeoutError):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
||||
|
||||
|
@ -140,7 +162,7 @@ def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
||||
|
||||
|
@ -154,5 +176,5 @@ def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
|
Loading…
Add table
Reference in a new issue