Skip to content

Commit

Permalink
fix(config_flow): when using auto, wrong device_id might be used (#239)
Browse files Browse the repository at this point in the history
* fix(config_flow): when using auto, wrong device_id might be used

* feat(config_flow): check if IP is the same for that device_id
  • Loading branch information
rokam authored Jul 16, 2024
1 parent 2fe6590 commit 79ccb02
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions custom_components/midea_ac_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,22 +607,31 @@ async def async_step_manually(
except ValueError:
return await self.async_step_manually(error="invalid_token")

device_id = user_input[CONF_DEVICE_ID]
# check device, discover already done or only manual add
if len(self.devices) < 1:
ip = user_input[CONF_IP_ADDRESS]
# discover device
self.devices = discover(
list(self.supports.keys()),
ip_address=user_input[CONF_IP_ADDRESS],
ip_address=ip,
)
# discover result MUST exist
if len(self.devices) != 1:
return await self.async_step_manually(error="invalid_device_ip")
# check all the input, disable error add
device_id = next(iter(self.devices.keys()))
# check all the input, disable error add
device_id = next(iter(self.devices.keys()))

# check if device_id is correctly set for that IP
if user_input[CONF_DEVICE_ID] != device_id:
return await self.async_step_manually(
error=f"For ip {ip} the device_id MUST be {device_id}",
)

device = self.devices[device_id]
if user_input[CONF_DEVICE_ID] != device_id:
if user_input[CONF_IP_ADDRESS] != device.get(CONF_IP_ADDRESS):
return await self.async_step_manually(
error=f"device_id MUST be {device_id}",
error=f"ip_address MUST be {device.get(CONF_IP_ADDRESS)}",
)
if user_input[CONF_PROTOCOL] != device.get(CONF_PROTOCOL):
return await self.async_step_manually(
Expand Down

0 comments on commit 79ccb02

Please sign in to comment.