Skip to content

Commit

Permalink
fix: usps_mail_delivered device_class (#923)
Browse files Browse the repository at this point in the history
* fix: usps_mail_delivered device_class

* disable sensor by default

* fix test
  • Loading branch information
firstof9 authored Jun 22, 2024
1 parent 66a146f commit 7d52bce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@
"usps_mail_delivered": BinarySensorEntityDescription(
name="USPS Mail Delivered",
key="usps_mail_delivered",
device_class=BinarySensorDeviceClass.UPDATE,
entity_registry_enabled_default=False,
),
}

Expand Down
22 changes: 21 additions & 1 deletion tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry
from homeassistant.helpers import entity_registry as er

from custom_components.mail_and_packages.const import DOMAIN
from tests.const import FAKE_CONFIG_DATA


@pytest.mark.asyncio
async def test_binary_sensor_no_updates(hass, mock_imap_no_email):
async def test_binary_sensor_no_updates(hass, mock_imap_no_email, entity_registry: er.EntityRegistry):
entry = MockConfigEntry(
domain=DOMAIN,
title="imap.test.email",
Expand All @@ -31,6 +32,25 @@ async def test_binary_sensor_no_updates(hass, mock_imap_no_email):
assert state
assert state.state == "off"

entity_entry = entity_registry.async_get("binary_sensor.usps_mail_delivered")

assert entity_entry
assert entity_entry.disabled
assert entity_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION

updated_entry = entity_registry.async_update_entity(
entity_entry.entity_id, disabled_by=None
)
assert updated_entry != entity_entry
assert updated_entry.disabled is False

# reload the integration
await hass.config_entries.async_forward_entry_unload(entry, "binary_sensor")
await hass.config_entries.async_forward_entry_setups(
entry, ["binary_sensor"]
)
await hass.async_block_till_done()

state = hass.states.get("binary_sensor.usps_mail_delivered")
assert state
assert state.state == "off"
Expand Down

0 comments on commit 7d52bce

Please sign in to comment.