mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add service to reset SmartTub reminders (#51824)
* Add service to reset SmartTub reminders * add test Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
a5362542ad
commit
da1d6d3821
@ -30,6 +30,11 @@ ATTR_UPDATED_AT = "updated_at"
|
|||||||
|
|
||||||
# how many days to snooze the reminder for
|
# how many days to snooze the reminder for
|
||||||
ATTR_REMINDER_DAYS = "days"
|
ATTR_REMINDER_DAYS = "days"
|
||||||
|
RESET_REMINDER_SCHEMA = {
|
||||||
|
vol.Required(ATTR_REMINDER_DAYS): vol.All(
|
||||||
|
vol.Coerce(int), vol.Range(min=30, max=365)
|
||||||
|
)
|
||||||
|
}
|
||||||
SNOOZE_REMINDER_SCHEMA = {
|
SNOOZE_REMINDER_SCHEMA = {
|
||||||
vol.Required(ATTR_REMINDER_DAYS): vol.All(
|
vol.Required(ATTR_REMINDER_DAYS): vol.All(
|
||||||
vol.Coerce(int), vol.Range(min=10, max=120)
|
vol.Coerce(int), vol.Range(min=10, max=120)
|
||||||
@ -60,6 +65,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
SNOOZE_REMINDER_SCHEMA,
|
SNOOZE_REMINDER_SCHEMA,
|
||||||
"async_snooze",
|
"async_snooze",
|
||||||
)
|
)
|
||||||
|
platform.async_register_entity_service(
|
||||||
|
"reset_reminder",
|
||||||
|
RESET_REMINDER_SCHEMA,
|
||||||
|
"async_reset",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity):
|
class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity):
|
||||||
@ -127,6 +137,11 @@ class SmartTubReminder(SmartTubEntity, BinarySensorEntity):
|
|||||||
await self.reminder.snooze(days)
|
await self.reminder.snooze(days)
|
||||||
await self.coordinator.async_request_refresh()
|
await self.coordinator.async_request_refresh()
|
||||||
|
|
||||||
|
async def async_reset(self, days):
|
||||||
|
"""Dismiss this reminder, and reset it to the specified number of days."""
|
||||||
|
await self.reminder.reset(days)
|
||||||
|
await self.coordinator.async_request_refresh()
|
||||||
|
|
||||||
|
|
||||||
class SmartTubError(SmartTubEntity, BinarySensorEntity):
|
class SmartTubError(SmartTubEntity, BinarySensorEntity):
|
||||||
"""Indicates whether an error code is present.
|
"""Indicates whether an error code is present.
|
||||||
|
@ -64,3 +64,22 @@ snooze_reminder:
|
|||||||
min: 10
|
min: 10
|
||||||
max: 120
|
max: 120
|
||||||
unit_of_measurement: days
|
unit_of_measurement: days
|
||||||
|
|
||||||
|
reset_reminder:
|
||||||
|
name: Reset a reminder
|
||||||
|
description: Reset a reminder, and set the next time it will be triggered.
|
||||||
|
target:
|
||||||
|
entity:
|
||||||
|
integration: smarttub
|
||||||
|
domain: binary_sensor
|
||||||
|
fields:
|
||||||
|
days:
|
||||||
|
name: Days
|
||||||
|
description: The number of days when the next reminder should trigger.
|
||||||
|
required: true
|
||||||
|
example: 180
|
||||||
|
selector:
|
||||||
|
number:
|
||||||
|
min: 30
|
||||||
|
max: 365
|
||||||
|
unit_of_measurement: days
|
||||||
|
@ -64,7 +64,7 @@ async def test_error(spa, hass, config_entry, mock_error):
|
|||||||
assert state.attributes["error_code"] == 11
|
assert state.attributes["error_code"] == 11
|
||||||
|
|
||||||
|
|
||||||
async def test_snooze(spa, setup_entry, hass):
|
async def test_snooze_reminder(spa, setup_entry, hass):
|
||||||
"""Test snoozing a reminder."""
|
"""Test snoozing a reminder."""
|
||||||
|
|
||||||
entity_id = f"binary_sensor.{spa.brand}_{spa.model}_myfilter_reminder"
|
entity_id = f"binary_sensor.{spa.brand}_{spa.model}_myfilter_reminder"
|
||||||
@ -76,9 +76,29 @@ async def test_snooze(spa, setup_entry, hass):
|
|||||||
"snooze_reminder",
|
"snooze_reminder",
|
||||||
{
|
{
|
||||||
"entity_id": entity_id,
|
"entity_id": entity_id,
|
||||||
"days": 30,
|
"days": days,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
reminder.snooze.assert_called_with(days)
|
reminder.snooze.assert_called_with(days)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_reset_reminder(spa, setup_entry, hass):
|
||||||
|
"""Test snoozing a reminder."""
|
||||||
|
|
||||||
|
entity_id = f"binary_sensor.{spa.brand}_{spa.model}_myfilter_reminder"
|
||||||
|
reminder = spa.get_reminders.return_value[0]
|
||||||
|
days = 180
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
"smarttub",
|
||||||
|
"reset_reminder",
|
||||||
|
{
|
||||||
|
"entity_id": entity_id,
|
||||||
|
"days": days,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
reminder.reset.assert_called_with(days)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user