Bump aiolifx to 0.8.7 and refactor config flow connection (#82818)

Signed-off-by: Avi Miller <me@dje.li>

Signed-off-by: Avi Miller <me@dje.li>
This commit is contained in:
Avi Miller 2022-11-29 03:27:27 +11:00 committed by GitHub
parent 63d519c1a8
commit 9849735dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -31,7 +31,7 @@ from .util import (
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for tplink.""" """Handle a config flow for LIFX."""
VERSION = 1 VERSION = 1
@ -41,7 +41,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._discovered_device: Light | None = None self._discovered_device: Light | None = None
async def async_step_dhcp(self, discovery_info: DhcpServiceInfo) -> FlowResult: async def async_step_dhcp(self, discovery_info: DhcpServiceInfo) -> FlowResult:
"""Handle discovery via dhcp.""" """Handle discovery via DHCP."""
mac = discovery_info.macaddress mac = discovery_info.macaddress
host = discovery_info.ip host = discovery_info.ip
hass = self.hass hass = self.hass
@ -70,8 +70,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_integration_discovery( async def async_step_integration_discovery(
self, discovery_info: DiscoveryInfoType self, discovery_info: DiscoveryInfoType
) -> FlowResult: ) -> FlowResult:
"""Handle discovery.""" """Handle LIFX UDP broadcast discovery."""
_LOGGER.debug("async_step_integration_discovery %s", discovery_info)
serial = discovery_info[CONF_SERIAL] serial = discovery_info[CONF_SERIAL]
host = discovery_info[CONF_HOST] host = discovery_info[CONF_HOST]
await self.async_set_unique_id(formatted_serial(serial)) 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 self, host: str, serial: str | None = None
) -> FlowResult: ) -> FlowResult:
"""Handle any discovery.""" """Handle any discovery."""
_LOGGER.debug("Discovery %s %s", host, serial)
self._async_abort_entries_match({CONF_HOST: host}) self._async_abort_entries_match({CONF_HOST: host})
self.context[CONF_HOST] = host self.context[CONF_HOST] = host
if any( if any(
@ -222,20 +220,30 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
except socket.gaierror: except socket.gaierror:
return None return None
device: Light = connection.device device: Light = connection.device
device.get_hostfirmware()
try: 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: except asyncio.TimeoutError:
return None return None
finally: finally:
connection.async_stop() connection.async_stop()
if ( 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 or device.host_firmware_version is None
): ):
return None # relays not supported return None # relays not supported
# device.mac_addr is not the mac_address, its the serial number # 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( await self.async_set_unique_id(
formatted_serial(device.mac_addr), raise_on_progress=raise_on_progress formatted_serial(device.mac_addr), raise_on_progress=raise_on_progress
) )

View File

@ -4,7 +4,7 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/lifx", "documentation": "https://www.home-assistant.io/integrations/lifx",
"requirements": [ "requirements": [
"aiolifx==0.8.6", "aiolifx==0.8.7",
"aiolifx_effects==0.3.0", "aiolifx_effects==0.3.0",
"aiolifx_themes==0.2.0" "aiolifx_themes==0.2.0"
], ],

View File

@ -193,7 +193,7 @@ aiokafka==0.7.2
aiokef==0.2.16 aiokef==0.2.16
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx==0.8.6 aiolifx==0.8.7
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx_effects==0.3.0 aiolifx_effects==0.3.0

View File

@ -171,7 +171,7 @@ aiohue==4.5.0
aiokafka==0.7.2 aiokafka==0.7.2
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx==0.8.6 aiolifx==0.8.7
# homeassistant.components.lifx # homeassistant.components.lifx
aiolifx_effects==0.3.0 aiolifx_effects==0.3.0

View File

@ -87,6 +87,7 @@ def _mocked_bulb() -> Light:
bulb.set_reboot = Mock() bulb.set_reboot = Mock()
bulb.try_sending = AsyncMock() bulb.try_sending = AsyncMock()
bulb.set_infrared = MockLifxCommand(bulb) bulb.set_infrared = MockLifxCommand(bulb)
bulb.get_label = MockLifxCommand(bulb)
bulb.get_color = MockLifxCommand(bulb) bulb.get_color = MockLifxCommand(bulb)
bulb.set_power = MockLifxCommand(bulb) bulb.set_power = MockLifxCommand(bulb)
bulb.set_color = MockLifxCommand(bulb) bulb.set_color = MockLifxCommand(bulb)