Skip to content

Commit

Permalink
fix: restore previous unique id structure in AlertSensor (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtimmy86x authored Oct 20, 2023
1 parent b4d4f38 commit 8e9f604
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/econnect_metronet/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def async_setup_entry(

# Iterate through the alerts of the provided device and create AlertSensor objects
for alert_id, name in device.alerts:
unique_id = f"{entry.entry_id}_{DOMAIN}_{q.ALERTS}_{alert_id}"
unique_id = f"{entry.entry_id}_{DOMAIN}_{name}"
sensors.append(AlertSensor(unique_id, alert_id, entry, name, coordinator, device))

async_add_entities(sensors)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_binary_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ def ensure_unused_sectors(sensors):
await async_setup_entry(hass, config_entry, ensure_unused_sectors)


@pytest.mark.asyncio
async def test_async_setup_entry_alerts_unique_id(hass, config_entry, alarm_device, coordinator):
# Regression test: changing this unique ID format is a breaking change
hass.data[DOMAIN][config_entry.entry_id] = {
"device": alarm_device,
"coordinator": coordinator,
}

# Test
def ensure_unused_sectors(sensors):
assert sensors[30].unique_id == "test_entry_id_econnect_metronet_tamper_led"

await async_setup_entry(hass, config_entry, ensure_unused_sectors)


class TestAlertSensor:
def test_binary_sensor_is_on(self, hass, config_entry, alarm_device):
# Ensure the sensor attribute is_on has the right status True
Expand Down

0 comments on commit 8e9f604

Please sign in to comment.