Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure unique_id is a string #251

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions custom_components/midea_ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
return True


async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Migrate config entry."""

_LOGGER.debug("Migrating configuration from version %s.%s.",
config_entry.version, config_entry.minor_version)

if config_entry.version > 1:
# Unsupported downgrade
return False

if config_entry.version == 1:
# 1.1 -> 1.2: Convert unique ID to string
if config_entry.minor_version == 1:
hass.config_entries.async_update_entry(
config_entry, unique_id=str(config_entry.unique_id), minor_version=2)

_LOGGER.debug("Migration to configuration version %s.%s successful.",
config_entry.version, config_entry.minor_version)

return True


async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Unload a config entry."""
# Remove the coordinator from global data
Expand Down
11 changes: 7 additions & 4 deletions custom_components/midea_ac/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
class MideaConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow for Midea Smart AC."""

VERSION = 1
MINOR_VERSION = 2

async def async_step_user(self, _) -> FlowResult:
"""Handle a config flow initialized by the user."""
return self.async_show_menu(
Expand Down Expand Up @@ -62,7 +65,7 @@ async def async_step_discover(
errors["base"] = "unsupported_device"
else:
# Check if device has already been configured
await self.async_set_unique_id(device.id)
await self.async_set_unique_id(str(device.id))
self._abort_if_unique_id_configured()

# Finish connection
Expand Down Expand Up @@ -92,7 +95,7 @@ async def async_step_pick_device(

if device:
# Check if device has already been configured
await self.async_set_unique_id(device.id)
await self.async_set_unique_id(str(device.id))
self._abort_if_unique_id_configured()

# Finish connection
Expand All @@ -116,7 +119,7 @@ async def async_step_pick_device(
f"{device.name} - {device.id} ({device.ip})"
)
for device in self._discovered_devices
if (device.id not in configured_devices and
if (str(device.id) not in configured_devices and
device.type == DeviceType.AIR_CONDITIONER)
}

Expand All @@ -140,7 +143,7 @@ async def async_step_manual(self, user_input) -> FlowResult:
id = int(user_input.get(CONF_ID))

# Check if device has already been configured
await self.async_set_unique_id(id)
await self.async_set_unique_id(str(id))
self._abort_if_unique_id_configured()

# Attempt a connection to see if config is valid
Expand Down