Skip to content

Commit

Permalink
Add service to reset SmartTub reminders (#51824)
Browse files Browse the repository at this point in the history
* Add service to reset SmartTub reminders

* add test

Co-authored-by: Franck Nijhof <git@frenck.dev>
  • Loading branch information
mdz and frenck committed Jun 27, 2021
1 parent a536254 commit da1d6d3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
15 changes: 15 additions & 0 deletions homeassistant/components/smarttub/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

# how many days to snooze the reminder for
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 = {
vol.Required(ATTR_REMINDER_DAYS): vol.All(
vol.Coerce(int), vol.Range(min=10, max=120)
Expand Down Expand Up @@ -60,6 +65,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
SNOOZE_REMINDER_SCHEMA,
"async_snooze",
)
platform.async_register_entity_service(
"reset_reminder",
RESET_REMINDER_SCHEMA,
"async_reset",
)


class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity):
Expand Down Expand Up @@ -127,6 +137,11 @@ async def async_snooze(self, days):
await self.reminder.snooze(days)
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):
"""Indicates whether an error code is present.
Expand Down
19 changes: 19 additions & 0 deletions homeassistant/components/smarttub/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ snooze_reminder:
min: 10
max: 120
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
24 changes: 22 additions & 2 deletions tests/components/smarttub/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def test_error(spa, hass, config_entry, mock_error):
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."""

entity_id = f"binary_sensor.{spa.brand}_{spa.model}_myfilter_reminder"
Expand All @@ -76,9 +76,29 @@ async def test_snooze(spa, setup_entry, hass):
"snooze_reminder",
{
"entity_id": entity_id,
"days": 30,
"days": days,
},
blocking=True,
)

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)

0 comments on commit da1d6d3

Please sign in to comment.