Add buttons to dismiss notifications in LaMetric (#80605)
This commit is contained in:
parent
05ef02bff6
commit
6ea6782d23
2 changed files with 118 additions and 0 deletions
|
@ -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(),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue