1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Add buttons to dismiss notifications in LaMetric (#80605)

This commit is contained in:
Franck Nijhof 2022-10-19 17:46:54 +02:00 committed by GitHub
parent 05ef02bff6
commit 6ea6782d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 0 deletions

View File

@ -48,6 +48,20 @@ BUTTONS = [
entity_category=EntityCategory.CONFIG,
press_fn=lambda api: api.app_previous(),
),
LaMetricButtonEntityDescription(
key="dismiss_current",
name="Dismiss current notification",
icon="mdi:bell-cancel",
entity_category=EntityCategory.CONFIG,
press_fn=lambda api: api.dismiss_current_notification(),
),
LaMetricButtonEntityDescription(
key="dismiss_all",
name="Dismiss all notifications",
icon="mdi:bell-cancel",
entity_category=EntityCategory.CONFIG,
press_fn=lambda api: api.dismiss_all_notifications(),
),
]

View File

@ -120,6 +120,110 @@ async def test_button_app_previous(
assert state.state == "2022-09-19T12:07:30+00:00"
@pytest.mark.freeze_time("2022-10-19 12:44:00")
async def test_button_dismiss_current_notification(
hass: HomeAssistant,
init_integration: MockConfigEntry,
mock_lametric: MagicMock,
) -> None:
"""Test the LaMetric dismiss current notification button."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
state = hass.states.get("button.frenck_s_lametric_dismiss_current_notification")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:bell-cancel"
assert state.state == STATE_UNKNOWN
entry = entity_registry.async_get(
"button.frenck_s_lametric_dismiss_current_notification"
)
assert entry
assert entry.unique_id == "SA110405124500W00BS9-dismiss_current"
assert entry.entity_category == EntityCategory.CONFIG
assert entry.device_id
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.configuration_url is None
assert device_entry.connections == {
(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")
}
assert device_entry.entry_type is None
assert device_entry.identifiers == {(DOMAIN, "SA110405124500W00BS9")}
assert device_entry.manufacturer == "LaMetric Inc."
assert device_entry.model == "LM 37X8"
assert device_entry.name == "Frenck's LaMetric"
assert device_entry.sw_version == "2.2.2"
assert device_entry.hw_version is None
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.frenck_s_lametric_dismiss_current_notification"},
blocking=True,
)
assert len(mock_lametric.dismiss_current_notification.mock_calls) == 1
mock_lametric.dismiss_current_notification.assert_called_with()
state = hass.states.get("button.frenck_s_lametric_dismiss_current_notification")
assert state
assert state.state == "2022-10-19T12:44:00+00:00"
@pytest.mark.freeze_time("2022-10-19 12:44:00")
async def test_button_dismiss_all_notifications(
hass: HomeAssistant,
init_integration: MockConfigEntry,
mock_lametric: MagicMock,
) -> None:
"""Test the LaMetric dismiss all notifications button."""
device_registry = dr.async_get(hass)
entity_registry = er.async_get(hass)
state = hass.states.get("button.frenck_s_lametric_dismiss_all_notifications")
assert state
assert state.attributes.get(ATTR_ICON) == "mdi:bell-cancel"
assert state.state == STATE_UNKNOWN
entry = entity_registry.async_get(
"button.frenck_s_lametric_dismiss_all_notifications"
)
assert entry
assert entry.unique_id == "SA110405124500W00BS9-dismiss_all"
assert entry.entity_category == EntityCategory.CONFIG
assert entry.device_id
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.configuration_url is None
assert device_entry.connections == {
(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")
}
assert device_entry.entry_type is None
assert device_entry.identifiers == {(DOMAIN, "SA110405124500W00BS9")}
assert device_entry.manufacturer == "LaMetric Inc."
assert device_entry.model == "LM 37X8"
assert device_entry.name == "Frenck's LaMetric"
assert device_entry.sw_version == "2.2.2"
assert device_entry.hw_version is None
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.frenck_s_lametric_dismiss_all_notifications"},
blocking=True,
)
assert len(mock_lametric.dismiss_all_notifications.mock_calls) == 1
mock_lametric.dismiss_all_notifications.assert_called_with()
state = hass.states.get("button.frenck_s_lametric_dismiss_all_notifications")
assert state
assert state.state == "2022-10-19T12:44:00+00:00"
@pytest.mark.freeze_time("2022-10-11 22:00:00")
async def test_button_error(
hass: HomeAssistant,