From 9849735dc5c93099c922caeb5e096a060569df89 Mon Sep 17 00:00:00 2001 From: Avi Miller Date: Tue, 29 Nov 2022 03:27:27 +1100 Subject: [PATCH] Bump aiolifx to 0.8.7 and refactor config flow connection (#82818) Signed-off-by: Avi Miller Signed-off-by: Avi Miller --- homeassistant/components/lifx/config_flow.py | 26 +++++++++++++------- homeassistant/components/lifx/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/lifx/__init__.py | 1 + 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/lifx/config_flow.py b/homeassistant/components/lifx/config_flow.py index 4b2a5b0895e..fa83ff5c427 100644 --- a/homeassistant/components/lifx/config_flow.py +++ b/homeassistant/components/lifx/config_flow.py @@ -31,7 +31,7 @@ from .util import ( class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): - """Handle a config flow for tplink.""" + """Handle a config flow for LIFX.""" VERSION = 1 @@ -41,7 +41,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self._discovered_device: Light | None = None async def async_step_dhcp(self, discovery_info: DhcpServiceInfo) -> FlowResult: - """Handle discovery via dhcp.""" + """Handle discovery via DHCP.""" mac = discovery_info.macaddress host = discovery_info.ip hass = self.hass @@ -70,8 +70,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_integration_discovery( self, discovery_info: DiscoveryInfoType ) -> FlowResult: - """Handle discovery.""" - _LOGGER.debug("async_step_integration_discovery %s", discovery_info) + """Handle LIFX UDP broadcast discovery.""" serial = discovery_info[CONF_SERIAL] host = discovery_info[CONF_HOST] await self.async_set_unique_id(formatted_serial(serial)) @@ -82,7 +81,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self, host: str, serial: str | None = None ) -> FlowResult: """Handle any discovery.""" - _LOGGER.debug("Discovery %s %s", host, serial) self._async_abort_entries_match({CONF_HOST: host}) self.context[CONF_HOST] = host if any( @@ -222,20 +220,30 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): except socket.gaierror: return None device: Light = connection.device - device.get_hostfirmware() try: - message = await async_execute_lifx(device.get_color) + # get_hostfirmware required for MAC address offset + # get_version required for lifx_features() + # get_label required to log the name of the device + messages = await asyncio.gather( + *[ + async_execute_lifx(device.get_hostfirmware), + async_execute_lifx(device.get_version), + async_execute_lifx(device.get_label), + ] + ) except asyncio.TimeoutError: return None finally: connection.async_stop() if ( - lifx_features(device)["relays"] is True + messages is None + or len(messages) != 3 + or lifx_features(device)["relays"] is True or device.host_firmware_version is None ): return None # relays not supported # device.mac_addr is not the mac_address, its the serial number - device.mac_addr = serial or message.target_addr + device.mac_addr = serial or messages[0].target_addr await self.async_set_unique_id( formatted_serial(device.mac_addr), raise_on_progress=raise_on_progress ) diff --git a/homeassistant/components/lifx/manifest.json b/homeassistant/components/lifx/manifest.json index fc5422757b9..c1e7cc56915 100644 --- a/homeassistant/components/lifx/manifest.json +++ b/homeassistant/components/lifx/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/lifx", "requirements": [ - "aiolifx==0.8.6", + "aiolifx==0.8.7", "aiolifx_effects==0.3.0", "aiolifx_themes==0.2.0" ], diff --git a/requirements_all.txt b/requirements_all.txt index 6ff981b2fa9..9ef78ad2afc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -193,7 +193,7 @@ aiokafka==0.7.2 aiokef==0.2.16 # homeassistant.components.lifx -aiolifx==0.8.6 +aiolifx==0.8.7 # homeassistant.components.lifx aiolifx_effects==0.3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index eac4ea03896..64aebb87f74 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -171,7 +171,7 @@ aiohue==4.5.0 aiokafka==0.7.2 # homeassistant.components.lifx -aiolifx==0.8.6 +aiolifx==0.8.7 # homeassistant.components.lifx aiolifx_effects==0.3.0 diff --git a/tests/components/lifx/__init__.py b/tests/components/lifx/__init__.py index 774376e1a99..bb861c4a683 100644 --- a/tests/components/lifx/__init__.py +++ b/tests/components/lifx/__init__.py @@ -87,6 +87,7 @@ def _mocked_bulb() -> Light: bulb.set_reboot = Mock() bulb.try_sending = AsyncMock() bulb.set_infrared = MockLifxCommand(bulb) + bulb.get_label = MockLifxCommand(bulb) bulb.get_color = MockLifxCommand(bulb) bulb.set_power = MockLifxCommand(bulb) bulb.set_color = MockLifxCommand(bulb)