mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Only set suggested area for new SmartThings devices (#145063)
This commit is contained in:
parent
be5685695e
commit
e80069545f
@ -32,6 +32,7 @@ from homeassistant.const import (
|
||||
ATTR_HW_VERSION,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
ATTR_SW_VERSION,
|
||||
ATTR_VIA_DEVICE,
|
||||
CONF_ACCESS_TOKEN,
|
||||
@ -454,14 +455,24 @@ def create_devices(
|
||||
ATTR_SW_VERSION: viper.software_version,
|
||||
}
|
||||
)
|
||||
if (
|
||||
device_registry.async_get_device({(DOMAIN, device.device.device_id)})
|
||||
is None
|
||||
):
|
||||
kwargs.update(
|
||||
{
|
||||
ATTR_SUGGESTED_AREA: (
|
||||
rooms.get(device.device.room_id)
|
||||
if device.device.room_id
|
||||
else None
|
||||
)
|
||||
}
|
||||
)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
identifiers={(DOMAIN, device.device.device_id)},
|
||||
configuration_url="https://account.smartthings.com",
|
||||
name=device.device.label,
|
||||
suggested_area=(
|
||||
rooms.get(device.device.room_id) if device.device.room_id else None
|
||||
),
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
@ -59,6 +59,37 @@ async def test_devices(
|
||||
assert device == snapshot
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000001"])
|
||||
async def test_device_not_resetting_area(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
devices: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""Test device not resetting area."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device_id = devices.get_devices.return_value[0].device_id
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, device_id)})
|
||||
|
||||
assert device.area_id == "theater"
|
||||
|
||||
device_registry.async_update_device(device_id=device.id, area_id=None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, device_id)})
|
||||
|
||||
assert device.area_id is None
|
||||
|
||||
await hass.config_entries.async_reload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, device_id)})
|
||||
assert device.area_id is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("device_fixture", ["button"])
|
||||
async def test_button_event(
|
||||
hass: HomeAssistant,
|
||||
|
Loading…
x
Reference in New Issue
Block a user