99import pytest
1010from syrupy .assertion import SnapshotAssertion
1111
12- from homeassistant .components .gios .const import SCAN_INTERVAL
12+ from homeassistant .components .gios .const import DOMAIN , SCAN_INTERVAL
1313from homeassistant .const import STATE_UNAVAILABLE , Platform
1414from homeassistant .core import HomeAssistant
1515from homeassistant .helpers import entity_registry as er
1616
17- from tests . common import MockConfigEntry , async_fire_time_changed , snapshot_platform
17+ from . import setup_integration
1818
19- pytestmark = pytest . mark . usefixtures ( "init_integration" )
19+ from tests . common import MockConfigEntry , async_fire_time_changed , snapshot_platform
2020
2121
2222@pytest .fixture (autouse = True )
@@ -26,6 +26,7 @@ def override_platforms() -> Generator[None]:
2626 yield
2727
2828
29+ @pytest .mark .usefixtures ("init_integration" )
2930async def test_sensor (
3031 hass : HomeAssistant ,
3132 entity_registry : er .EntityRegistry ,
@@ -36,6 +37,7 @@ async def test_sensor(
3637 await snapshot_platform (hass , entity_registry , snapshot , mock_config_entry .entry_id )
3738
3839
40+ @pytest .mark .usefixtures ("init_integration" )
3941async def test_availability (hass : HomeAssistant ) -> None :
4042 """Ensure that we mark the entities unavailable correctly when service causes an error."""
4143 state = hass .states .get ("sensor.home_pm2_5" )
@@ -51,6 +53,7 @@ async def test_availability(hass: HomeAssistant) -> None:
5153 assert state .state == "good"
5254
5355
56+ @pytest .mark .usefixtures ("init_integration" )
5457async def test_availability_api_error (
5558 hass : HomeAssistant ,
5659 mock_gios : MagicMock ,
@@ -124,3 +127,25 @@ async def test_availability_api_error(
124127 state = hass .states .get ("sensor.home_air_quality_index" )
125128 assert state
126129 assert state .state == "good"
130+
131+
132+ async def test_unique_id_migration (
133+ hass : HomeAssistant ,
134+ entity_registry : er .EntityRegistry ,
135+ mock_gios : MagicMock ,
136+ mock_config_entry : MockConfigEntry ,
137+ ) -> None :
138+ """Test states of the unique_id migration."""
139+ entity_registry .async_get_or_create (
140+ Platform .SENSOR ,
141+ DOMAIN ,
142+ "123-pm2.5" ,
143+ suggested_object_id = "home_pm2_5" ,
144+ disabled_by = None ,
145+ )
146+
147+ await setup_integration (hass , mock_config_entry )
148+
149+ entry = entity_registry .async_get ("sensor.home_pm2_5" )
150+ assert entry
151+ assert entry .unique_id == "123-pm25"
0 commit comments