From dfe3219f3f39254b30468dc273285ce936c952e3 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Mar 2018 14:00:56 -0700 Subject: [PATCH 1/6] Hue: Convert XY to HS color if HS not present (#13465) * Hue: Convert XY to HS color if HS not present * Revert change to test * Address comments * Lint --- homeassistant/components/light/hue.py | 30 ++++++++------ tests/components/light/test_hue.py | 57 +++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 71e3d4fa30b..4a54f0a337d 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -18,6 +18,7 @@ from homeassistant.components.light import ( FLASH_LONG, FLASH_SHORT, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_EFFECT, SUPPORT_FLASH, SUPPORT_COLOR, SUPPORT_TRANSITION, Light) +from homeassistant.util import color DEPENDENCIES = ['hue'] SCAN_INTERVAL = timedelta(seconds=5) @@ -235,19 +236,26 @@ class HueLight(Light): @property def hs_color(self): """Return the hs color value.""" - # Don't return hue/sat if in color temperature mode - if self._color_mode == "ct": + # pylint: disable=redefined-outer-name + mode = self._color_mode + + if mode not in ('hs', 'xy'): + return + + source = self.light.action if self.is_group else self.light.state + + hue = source.get('hue') + sat = source.get('sat') + + # Sometimes the state will not include valid hue/sat values. + # Reported as issue 13434 + if hue is not None and sat is not None: + return hue / 65535 * 360, sat / 255 * 100 + + if 'xy' not in source: return None - if self.is_group: - return ( - self.light.action.get('hue') / 65535 * 360, - self.light.action.get('sat') / 255 * 100, - ) - return ( - self.light.state.get('hue') / 65535 * 360, - self.light.state.get('sat') / 255 * 100, - ) + return color.color_xy_to_hs(*source['xy']) @property def color_temp(self): diff --git a/tests/components/light/test_hue.py b/tests/components/light/test_hue.py index 54bb2184a64..d73531b1b9a 100644 --- a/tests/components/light/test_hue.py +++ b/tests/components/light/test_hue.py @@ -11,6 +11,7 @@ import pytest from homeassistant.components import hue import homeassistant.components.light.hue as hue_light +from homeassistant.util import color _LOGGER = logging.getLogger(__name__) @@ -623,3 +624,59 @@ def test_available(): ) assert light.available is True + + +def test_hs_color(): + """Test hs_color property.""" + light = hue_light.HueLight( + light=Mock(state={ + 'colormode': 'ct', + 'hue': 1234, + 'sat': 123, + }), + request_bridge_update=None, + bridge=Mock(), + is_group=False, + ) + + assert light.hs_color is None + + light = hue_light.HueLight( + light=Mock(state={ + 'colormode': 'hs', + 'hue': 1234, + 'sat': 123, + }), + request_bridge_update=None, + bridge=Mock(), + is_group=False, + ) + + assert light.hs_color == (1234 / 65535 * 360, 123 / 255 * 100) + + light = hue_light.HueLight( + light=Mock(state={ + 'colormode': 'xy', + 'hue': 1234, + 'sat': 123, + }), + request_bridge_update=None, + bridge=Mock(), + is_group=False, + ) + + assert light.hs_color == (1234 / 65535 * 360, 123 / 255 * 100) + + light = hue_light.HueLight( + light=Mock(state={ + 'colormode': 'xy', + 'hue': None, + 'sat': 123, + 'xy': [0.4, 0.5] + }), + request_bridge_update=None, + bridge=Mock(), + is_group=False, + ) + + assert light.hs_color == color.color_xy_to_hs(0.4, 0.5) From f48ce3d437c5bcfcbd4eb4d2ff6ca7756dd93966 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Tue, 27 Mar 2018 01:08:44 +0200 Subject: [PATCH 2/6] Fix ID (fixes #13444) (#13471) --- homeassistant/components/media_player/mpchc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/media_player/mpchc.py b/homeassistant/components/media_player/mpchc.py index cc195db2590..a375a585ad4 100644 --- a/homeassistant/components/media_player/mpchc.py +++ b/homeassistant/components/media_player/mpchc.py @@ -155,8 +155,8 @@ class MpcHcDevice(MediaPlayerDevice): def media_next_track(self): """Send next track command.""" - self._send_command(921) + self._send_command(920) def media_previous_track(self): """Send previous track command.""" - self._send_command(920) + self._send_command(919) From ce3a5972c787b1cc854d0ae1deb3558b28a816f7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Mar 2018 16:07:22 -0700 Subject: [PATCH 3/6] Upgrade aiohue and fix race condition (#13475) * Bump aiohue to 1.3 * Store bridge in hass.data before setting up platform * Fix tests --- homeassistant/components/hue/__init__.py | 5 +++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/hue/test_bridge.py | 1 + tests/components/hue/test_setup.py | 6 +----- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/hue/__init__.py b/homeassistant/components/hue/__init__.py index 2fb55f8f6e0..b70021e0304 100644 --- a/homeassistant/components/hue/__init__.py +++ b/homeassistant/components/hue/__init__.py @@ -21,7 +21,7 @@ from homeassistant.helpers import discovery, aiohttp_client from homeassistant import config_entries from homeassistant.util.json import save_json -REQUIREMENTS = ['aiohue==1.2.0'] +REQUIREMENTS = ['aiohue==1.3.0'] _LOGGER = logging.getLogger(__name__) @@ -145,7 +145,6 @@ async def async_setup_bridge( bridge = HueBridge(host, hass, filename, username, allow_unreachable, allow_hue_groups) await bridge.async_setup() - hass.data[DOMAIN][host] = bridge def _find_username_from_config(hass, filename): @@ -209,6 +208,8 @@ class HueBridge(object): self.host) return + self.hass.data[DOMAIN][self.host] = self + # If we came here and configuring this host, mark as done if self.config_request_id: request_id = self.config_request_id diff --git a/requirements_all.txt b/requirements_all.txt index 017449bfeca..e30b70eb976 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -74,7 +74,7 @@ aiodns==1.1.1 aiohttp_cors==0.7.0 # homeassistant.components.hue -aiohue==1.2.0 +aiohue==1.3.0 # homeassistant.components.sensor.imap aioimaplib==0.7.13 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index fda514af007..27d3bd21ad7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -35,7 +35,7 @@ aioautomatic==0.6.5 aiohttp_cors==0.7.0 # homeassistant.components.hue -aiohue==1.2.0 +aiohue==1.3.0 # homeassistant.components.notify.apns apns2==0.3.0 diff --git a/tests/components/hue/test_bridge.py b/tests/components/hue/test_bridge.py index 88a7223d91e..39351699df5 100644 --- a/tests/components/hue/test_bridge.py +++ b/tests/components/hue/test_bridge.py @@ -66,6 +66,7 @@ async def test_only_create_no_username(hass): async def test_configurator_callback(hass, mock_request): """.""" + hass.data[hue.DOMAIN] = {} with patch('aiohue.Bridge.create_user', side_effect=aiohue.LinkButtonNotPressed): await MockBridge(hass).async_setup() diff --git a/tests/components/hue/test_setup.py b/tests/components/hue/test_setup.py index 690419fcb7a..f90f58a50c3 100644 --- a/tests/components/hue/test_setup.py +++ b/tests/components/hue/test_setup.py @@ -18,7 +18,6 @@ async def test_setup_with_multiple_hosts(hass, mock_bridge): assert len(mock_bridge.mock_calls) == 2 hosts = sorted(mock_call[1][0] for mock_call in mock_bridge.mock_calls) assert hosts == ['127.0.0.1', '192.168.1.10'] - assert len(hass.data[hue.DOMAIN]) == 2 async def test_bridge_discovered(hass, mock_bridge): @@ -33,7 +32,6 @@ async def test_bridge_discovered(hass, mock_bridge): assert len(mock_bridge.mock_calls) == 1 assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10' - assert len(hass.data[hue.DOMAIN]) == 1 async def test_bridge_configure_and_discovered(hass, mock_bridge): @@ -48,7 +46,7 @@ async def test_bridge_configure_and_discovered(hass, mock_bridge): assert len(mock_bridge.mock_calls) == 1 assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10' - assert len(hass.data[hue.DOMAIN]) == 1 + hass.data[hue.DOMAIN] = {'192.168.1.10': {}} mock_bridge.reset_mock() @@ -59,7 +57,6 @@ async def test_bridge_configure_and_discovered(hass, mock_bridge): await hass.async_block_till_done() assert len(mock_bridge.mock_calls) == 0 - assert len(hass.data[hue.DOMAIN]) == 1 async def test_setup_no_host(hass, aioclient_mock): @@ -71,4 +68,3 @@ async def test_setup_no_host(hass, aioclient_mock): assert result assert len(aioclient_mock.mock_calls) == 1 - assert len(hass.data[hue.DOMAIN]) == 0 From a06eea444af977c8513db2fe7c1593da816bec0e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Mar 2018 14:55:09 -0700 Subject: [PATCH 4/6] version should contain just 'b' not 'beta' (#13476) --- script/version_bump.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/script/version_bump.py b/script/version_bump.py index 0cd02ddbfcb..0500fc45957 100755 --- a/script/version_bump.py +++ b/script/version_bump.py @@ -23,7 +23,7 @@ def bump_version(cur_major, cur_minor, cur_patch, bump_type): if bump_type == 'release_patch': # Convert 0.67.3 to 0.67.4 - # Convert 0.67.3.beta5 to 0.67.3 + # Convert 0.67.3.b5 to 0.67.3 # Convert 0.67.3.dev0 to 0.67.3 new_major = cur_major new_minor = cur_minor @@ -35,7 +35,7 @@ def bump_version(cur_major, cur_minor, cur_patch, bump_type): elif bump_type == 'dev': # Convert 0.67.3 to 0.67.4.dev0 - # Convert 0.67.3.beta5 to 0.67.4.dev0 + # Convert 0.67.3.b5 to 0.67.4.dev0 # Convert 0.67.3.dev0 to 0.67.3.dev1 new_major = cur_major @@ -48,22 +48,22 @@ def bump_version(cur_major, cur_minor, cur_patch, bump_type): new_patch = '0.dev0' elif bump_type == 'beta': - # Convert 0.67.5 to 0.67.8.beta0 - # Convert 0.67.0.dev0 to 0.67.0.beta0 - # Convert 0.67.5.beta4 to 0.67.5.beta5 + # Convert 0.67.5 to 0.67.8.b0 + # Convert 0.67.0.dev0 to 0.67.0.b0 + # Convert 0.67.5.b4 to 0.67.5.b5 new_major = cur_major new_minor = cur_minor if patch_parts['prerel'] is None: patch_parts['patch'] += 1 - patch_parts['prerel'] = 'beta' + patch_parts['prerel'] = 'b' patch_parts['prerelversion'] = 0 - elif patch_parts['prerel'] == 'beta': + elif patch_parts['prerel'] == 'b': patch_parts['prerelversion'] += 1 elif patch_parts['prerel'] == 'dev': - patch_parts['prerel'] = 'beta' + patch_parts['prerel'] = 'b' patch_parts['prerelversion'] = 0 else: @@ -110,22 +110,22 @@ def main(): def test_bump_version(): """Make sure it all works.""" assert bump_version(0, 56, '0', 'beta') == \ - (0, 56, '1.beta0') - assert bump_version(0, 56, '0.beta3', 'beta') == \ - (0, 56, '0.beta4') + (0, 56, '1.b0') + assert bump_version(0, 56, '0.b3', 'beta') == \ + (0, 56, '0.b4') assert bump_version(0, 56, '0.dev0', 'beta') == \ - (0, 56, '0.beta0') + (0, 56, '0.b0') assert bump_version(0, 56, '3', 'dev') == \ (0, 57, '0.dev0') - assert bump_version(0, 56, '0.beta3', 'dev') == \ + assert bump_version(0, 56, '0.b3', 'dev') == \ (0, 57, '0.dev0') assert bump_version(0, 56, '0.dev0', 'dev') == \ (0, 56, '0.dev1') assert bump_version(0, 56, '3', 'release_patch') == \ (0, 56, '4') - assert bump_version(0, 56, '3.beta3', 'release_patch') == \ + assert bump_version(0, 56, '3.b3', 'release_patch') == \ (0, 56, '3') assert bump_version(0, 56, '0.dev0', 'release_patch') == \ (0, 56, '0') From 94d9aa0c5fe023725d74beb6a61402f3b1169a3b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Mar 2018 16:10:03 -0700 Subject: [PATCH 5/6] Bump version to 0.66.0.b2 --- homeassistant/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/const.py b/homeassistant/const.py index 382323ed534..58c49289989 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -2,7 +2,7 @@ """Constants used by Home Assistant components.""" MAJOR_VERSION = 0 MINOR_VERSION = 66 -PATCH_VERSION = '0.beta1' +PATCH_VERSION = '0.b2' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION) REQUIRED_PYTHON_VER = (3, 5, 3) From 3639a4470c6c626414a8c4018f455e3f79b59170 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Mar 2018 16:16:42 -0700 Subject: [PATCH 6/6] Use twine for release --- script/release | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/release b/script/release index 17d5ad9370d..dc3e208bc1a 100755 --- a/script/release +++ b/script/release @@ -27,4 +27,5 @@ then exit 1 fi -python3 setup.py sdist bdist_wheel upload +python3 setup.py sdist bdist_wheel +python3 -m twine upload dist/* --skip-existing