Skip to content

Commit

Permalink
Release v4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwetering committed May 8, 2022
2 parents 36212bb + 93b46e6 commit 23b16cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/yamaha_ynca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
registry.async_remove(entity.entity_id)

config_entry.version = 3
hass.config_entries.async_update_entry(config_entry, data=new)
hass.config_entries.async_update_entry(config_entry, data=config_entry.data)

LOGGER.info("Migration to version %s successful", config_entry.version)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/yamaha_ynca/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"@mvdwetering"
],
"iot_class": "local_push",
"version": "4.0.1"
"version": "4.0.2"
}
50 changes: 46 additions & 4 deletions tests/test_init_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,52 @@ async def test_async_migration_entry_version_1(hass: HomeAssistant):
assert migration_success

# Serial_port renamed to serial_url
entry_v2 = hass.config_entries.async_get_entry(entry_v1.entry_id)
assert entry_v2.version == 3
assert entry_v2.title == entry_v1.title
assert entry_v2.data["serial_url"] == "SerialPort"
entry_v3 = hass.config_entries.async_get_entry(entry_v1.entry_id)
assert entry_v3.version == 3
assert entry_v3.title == entry_v1.title
assert entry_v3.data["serial_url"] == "SerialPort"

# Button and Scene entities removed
assert len(mock_entity_registry.entities) == 0


async def test_async_migration_entry_version_2(hass: HomeAssistant):
"""Test a successful setup entry."""

entry_v2 = MockConfigEntry(
domain=yamaha_ynca.DOMAIN,
entry_id="entry_id",
title="ModelName",
data={"serial_url": "SerialUrl"},
version=2,
)
entry_v2.add_to_hass(hass)

mock_entity_registry = mock_registry(hass)
mock_scene_entity_entry = mock_entity_registry.async_get_or_create(
Platform.SCENE,
yamaha_ynca.DOMAIN,
"scene.scene_button",
config_entry=entry_v2,
device_id="device_id",
)
assert len(mock_entity_registry.entities) == 1 # Make sure entities were added

# Migrate
with patch(
"homeassistant.helpers.entity_registry.async_get",
return_value=mock_entity_registry,
):
migration_success = await yamaha_ynca.async_migrate_entry(hass, entry_v2)
await hass.async_block_till_done()

assert migration_success

# Serial_port renamed to serial_url
entry_v3 = hass.config_entries.async_get_entry(entry_v2.entry_id)
assert entry_v3.version == 3
assert entry_v3.title == entry_v2.title
assert entry_v3.data["serial_url"] == "SerialUrl"

# Scene entities removed
assert len(mock_entity_registry.entities) == 0

0 comments on commit 23b16cc

Please sign in to comment.