Skip to content

Commit 4906e78

Browse files
joostlekfrenck
authored andcommitted
Only set suggested area for new SmartThings devices (home-assistant#145063)
1 parent 146e440 commit 4906e78

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

homeassistant/components/smartthings/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ATTR_HW_VERSION,
3333
ATTR_MANUFACTURER,
3434
ATTR_MODEL,
35+
ATTR_SUGGESTED_AREA,
3536
ATTR_SW_VERSION,
3637
ATTR_VIA_DEVICE,
3738
CONF_ACCESS_TOKEN,
@@ -453,14 +454,24 @@ def create_devices(
453454
ATTR_SW_VERSION: viper.software_version,
454455
}
455456
)
457+
if (
458+
device_registry.async_get_device({(DOMAIN, device.device.device_id)})
459+
is None
460+
):
461+
kwargs.update(
462+
{
463+
ATTR_SUGGESTED_AREA: (
464+
rooms.get(device.device.room_id)
465+
if device.device.room_id
466+
else None
467+
)
468+
}
469+
)
456470
device_registry.async_get_or_create(
457471
config_entry_id=entry.entry_id,
458472
identifiers={(DOMAIN, device.device.device_id)},
459473
configuration_url="https://account.smartthings.com",
460474
name=device.device.label,
461-
suggested_area=(
462-
rooms.get(device.device.room_id) if device.device.room_id else None
463-
),
464475
**kwargs,
465476
)
466477

tests/components/smartthings/test_init.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,37 @@ async def test_devices(
5959
assert device == snapshot
6060

6161

62+
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
63+
async def test_device_not_resetting_area(
64+
hass: HomeAssistant,
65+
snapshot: SnapshotAssertion,
66+
devices: AsyncMock,
67+
mock_config_entry: MockConfigEntry,
68+
device_registry: dr.DeviceRegistry,
69+
) -> None:
70+
"""Test device not resetting area."""
71+
await setup_integration(hass, mock_config_entry)
72+
73+
device_id = devices.get_devices.return_value[0].device_id
74+
75+
device = device_registry.async_get_device({(DOMAIN, device_id)})
76+
77+
assert device.area_id == "theater"
78+
79+
device_registry.async_update_device(device_id=device.id, area_id=None)
80+
await hass.async_block_till_done()
81+
82+
device = device_registry.async_get_device({(DOMAIN, device_id)})
83+
84+
assert device.area_id is None
85+
86+
await hass.config_entries.async_reload(mock_config_entry.entry_id)
87+
await hass.async_block_till_done()
88+
89+
device = device_registry.async_get_device({(DOMAIN, device_id)})
90+
assert device.area_id is None
91+
92+
6293
@pytest.mark.parametrize("device_fixture", ["button"])
6394
async def test_button_event(
6495
hass: HomeAssistant,

0 commit comments

Comments
 (0)