Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions homeassistant/components/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ATTR_RELEASE_NOTES = 'release_notes'

CONF_REPORTING = 'reporting'
CONF_COMPONENT_REPORTING = 'include_used_components'

DOMAIN = 'updater'

Expand All @@ -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({
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -116,7 +121,7 @@ def check_new_version(now):


@asyncio.coroutine
def get_system_info(hass):
def get_system_info(hass, include_components):
"""Return info about the system."""
info_object = {
'arch': platform.machine(),
Expand All @@ -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':
Expand All @@ -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 = {}
Expand Down
32 changes: 27 additions & 5 deletions tests/components/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
'version': '0.15',
'release-notes': 'https://home-assistant.io'
}
MOCK_CONFIG = {updater.DOMAIN: {
'reporting': True
}}


@pytest.fixture
Expand Down Expand Up @@ -94,19 +97,38 @@ 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."""
aioclient_mock.post(updater.UPDATER_URL, json=MOCK_RESPONSE)

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'])

Expand All @@ -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'])

Expand All @@ -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


Expand All @@ -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


Expand All @@ -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