Skip to content

Commit

Permalink
fix issues with removing and re-adding robots in the config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey0000 committed Aug 8, 2024
1 parent eda7e43 commit b52c2e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions custom_components/mammotion/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MammotionConfigFlow(ConfigFlow, domain=DOMAIN):
def __init__(self) -> None:
"""Initialize the config flow."""
self._discovered_device: BLEDevice | None = None
self._discovered_devices: dict[str, str] = {}


async def async_step_bluetooth(
self, discovery_info: BluetoothServiceInfo
Expand Down Expand Up @@ -74,14 +76,13 @@ async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the user step to pick discovered device."""
discovered_devices: dict[str, str] = {}

if user_input is not None:
address = user_input[CONF_ADDRESS]
await self.async_set_unique_id(address, raise_on_progress=False)
self._abort_if_unique_id_configured()

name = discovered_devices.get(address)
name = self._discovered_devices.get(address)
if name is None:
return self.async_abort(reason="no_longer_present")

Expand All @@ -95,19 +96,19 @@ async def async_step_user(
current_addresses = self._async_current_ids()
for discovery_info in async_discovered_service_info(self.hass):
address = discovery_info.address
if address in current_addresses or address in discovered_devices:
if address in current_addresses or address in self._discovered_devices:
continue

discovered_devices[address] = discovery_info.name
self._discovered_devices[address] = discovery_info.name

if not discovered_devices:
if not self._discovered_devices:
return self.async_abort(reason="no_devices_found")

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_ADDRESS): vol.In(discovered_devices),
vol.Required(CONF_ADDRESS): vol.In(self._discovered_devices),
},
),
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Mammotion-HA"
version = "0.0.10"
version = "0.0.12"
description = "Mammotion lawn mower integration for HACS"
authors = ["Michael Arthur <michael@jumblesoft.co.nz>", "jLynx <@jlynx>"]
readme = "README.md"
Expand Down

0 comments on commit b52c2e1

Please sign in to comment.