From a68dd94eb5ebcf46808489f255bacdf496328e27 Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Mon, 22 May 2017 12:35:36 -0700 Subject: [PATCH 1/4] Setup to send component data is option is enabled --- homeassistant/components/updater.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/updater.py b/homeassistant/components/updater.py index 137757fdbd473b..4e5f7a0f545bc6 100644 --- a/homeassistant/components/updater.py +++ b/homeassistant/components/updater.py @@ -32,6 +32,7 @@ ATTR_RELEASE_NOTES = 'release_notes' CONF_REPORTING = 'reporting' +CONF_COMPONENT_REPORTING = 'share_components_info' DOMAIN = 'updater' @@ -41,7 +42,8 @@ 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({ @@ -86,7 +88,7 @@ def async_setup(hass, config): @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, config) if result is None: return @@ -116,7 +118,7 @@ def check_new_version(now): @asyncio.coroutine -def get_system_info(hass): +def get_system_info(hass, config): """Return info about the system.""" info_object = { 'arch': platform.machine(), @@ -129,6 +131,9 @@ def get_system_info(hass): 'virtualenv': os.environ.get('VIRTUAL_ENV') is not None, } + if config.get(CONF_COMPONENT_REPORTING): + 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 +152,10 @@ def get_system_info(hass): @asyncio.coroutine -def get_newest_version(hass, huuid): +def get_newest_version(hass, huuid, config): """Get the newest Home Assistant version.""" if huuid: - info_object = yield from get_system_info(hass) + info_object = yield from get_system_info(hass, config) info_object['huuid'] = huuid else: info_object = {} From f209ffc55a26fe849a6c7fa38e26b4542f9e7403 Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Mon, 22 May 2017 15:41:36 -0700 Subject: [PATCH 2/4] testcases, as well as moved to a single boolean, passed to the function --- homeassistant/components/updater.py | 15 ++++++++++----- tests/components/test_updater.py | 30 ++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/updater.py b/homeassistant/components/updater.py index 4e5f7a0f545bc6..52707be6b52fd2 100644 --- a/homeassistant/components/updater.py +++ b/homeassistant/components/updater.py @@ -85,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, config) + result = yield from get_newest_version(hass, huuid, + include_components) if result is None: return @@ -118,7 +121,7 @@ def check_new_version(now): @asyncio.coroutine -def get_system_info(hass, config): +def get_system_info(hass, include_components): """Return info about the system.""" info_object = { 'arch': platform.machine(), @@ -131,8 +134,10 @@ def get_system_info(hass, config): 'virtualenv': os.environ.get('VIRTUAL_ENV') is not None, } - if config.get(CONF_COMPONENT_REPORTING): + if include_components: info_object['components'] = list(hass.config.components) + #info_object['components'] = list(hass.config.components) + if platform.system() == 'Windows': info_object['os_version'] = platform.win32_ver()[0] @@ -152,10 +157,10 @@ def get_system_info(hass, config): @asyncio.coroutine -def get_newest_version(hass, huuid, config): +def get_newest_version(hass, huuid, include_components): """Get the newest Home Assistant version.""" if huuid: - info_object = yield from get_system_info(hass, config) + info_object = yield from get_system_info(hass, include_components) info_object['huuid'] = huuid else: info_object = {} diff --git a/tests/components/test_updater.py b/tests/components/test_updater.py index 8cc1c78cdcbf4e..627bf55a339a69 100644 --- a/tests/components/test_updater.py +++ b/tests/components/test_updater.py @@ -19,6 +19,9 @@ 'version': '0.15', 'release-notes': 'https://home-assistant.io' } +MOCK_CONFIG = {updater.DOMAIN: { + 'reporting': True +}} @pytest.fixture @@ -94,11 +97,28 @@ 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 to NOT generate component list' + + @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 +126,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 +138,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 +149,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 +160,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 +174,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 From 6438fc36d12de614cd5b92a48966cec75e434346 Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Mon, 22 May 2017 15:49:12 -0700 Subject: [PATCH 3/4] fixed pep8 failures --- homeassistant/components/updater.py | 4 +--- tests/components/test_updater.py | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/updater.py b/homeassistant/components/updater.py index 52707be6b52fd2..65f5c4d2038e3a 100644 --- a/homeassistant/components/updater.py +++ b/homeassistant/components/updater.py @@ -90,7 +90,7 @@ def async_setup(hass, config): @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: @@ -136,8 +136,6 @@ def get_system_info(hass, include_components): if include_components: info_object['components'] = list(hass.config.components) - #info_object['components'] = list(hass.config.components) - if platform.system() == 'Windows': info_object['os_version'] = platform.win32_ver()[0] diff --git a/tests/components/test_updater.py b/tests/components/test_updater.py index 627bf55a339a69..8dfe309527ad7a 100644 --- a/tests/components/test_updater.py +++ b/tests/components/test_updater.py @@ -106,7 +106,8 @@ def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version): @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")): + 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' @@ -114,9 +115,10 @@ def test_enabled_component_info(hass, mock_get_uuid): @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")): + 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 to NOT generate component list' + assert 'components' not in res, 'Updater failed, components generate' @asyncio.coroutine From a0ad24df7a3eeb25f6789a8c650cf9e451f8ad20 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 4 Jun 2017 23:29:48 -0700 Subject: [PATCH 4/4] Clarify config option. --- homeassistant/components/updater.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/updater.py b/homeassistant/components/updater.py index 65f5c4d2038e3a..4ce59b6f8f10f3 100644 --- a/homeassistant/components/updater.py +++ b/homeassistant/components/updater.py @@ -32,7 +32,7 @@ ATTR_RELEASE_NOTES = 'release_notes' CONF_REPORTING = 'reporting' -CONF_COMPONENT_REPORTING = 'share_components_info' +CONF_COMPONENT_REPORTING = 'include_used_components' DOMAIN = 'updater'