diff --git a/homeassistant/components/smarttub/binary_sensor.py b/homeassistant/components/smarttub/binary_sensor.py index 31c6f6d0bc0..2ca2e10245c 100644 --- a/homeassistant/components/smarttub/binary_sensor.py +++ b/homeassistant/components/smarttub/binary_sensor.py @@ -2,12 +2,14 @@ import logging from smarttub import SpaReminder +import voluptuous as vol from homeassistant.components.binary_sensor import ( DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_PROBLEM, BinarySensorEntity, ) +from homeassistant.helpers import entity_platform from .const import ATTR_REMINDERS, DOMAIN, SMARTTUB_CONTROLLER from .entity import SmartTubEntity, SmartTubSensorBase @@ -17,6 +19,12 @@ _LOGGER = logging.getLogger(__name__) # whether the reminder has been snoozed (bool) ATTR_REMINDER_SNOOZED = "snoozed" +# how many days to snooze the reminder for +ATTR_SNOOZE_DAYS = "days" +SNOOZE_REMINDER_SCHEMA = { + vol.Required(ATTR_SNOOZE_DAYS): vol.All(vol.Coerce(int), vol.Range(min=10, max=120)) +} + async def async_setup_entry(hass, entry, async_add_entities): """Set up binary sensor entities for the binary sensors in the tub.""" @@ -33,6 +41,14 @@ async def async_setup_entry(hass, entry, async_add_entities): async_add_entities(entities) + platform = entity_platform.current_platform.get() + + platform.async_register_entity_service( + "snooze_reminder", + SNOOZE_REMINDER_SCHEMA, + "async_snooze", + ) + class SmartTubOnline(SmartTubSensorBase, BinarySensorEntity): """A binary sensor indicating whether the spa is currently online (connected to the cloud).""" @@ -98,3 +114,9 @@ class SmartTubReminder(SmartTubEntity, BinarySensorEntity): def device_class(self) -> str: """Return the device class for this entity.""" return DEVICE_CLASS_PROBLEM + + async def async_snooze(self, **kwargs): + """Snooze this reminder for the specified number of days.""" + days = kwargs[ATTR_SNOOZE_DAYS] + await self.reminder.snooze(days) + await self.coordinator.async_request_refresh() diff --git a/homeassistant/components/smarttub/services.yaml b/homeassistant/components/smarttub/services.yaml index 30bd225113e..bb5ee66f1d0 100644 --- a/homeassistant/components/smarttub/services.yaml +++ b/homeassistant/components/smarttub/services.yaml @@ -45,3 +45,22 @@ set_secondary_filtration: - "away" required: true example: "frequent" + +snooze_reminder: + name: Snooze a reminder + description: Delay a reminder, so that it won't trigger again for a period of time. + target: + entity: + integration: smarttub + domain: binary_sensor + fields: + days: + name: Days + description: The number of days to delay the reminder. + required: true + example: 7 + selector: + number: + min: 10 + max: 120 + unit_of_measurement: days diff --git a/tests/components/smarttub/test_binary_sensor.py b/tests/components/smarttub/test_binary_sensor.py index b5a7c516a0e..b39986ef394 100644 --- a/tests/components/smarttub/test_binary_sensor.py +++ b/tests/components/smarttub/test_binary_sensor.py @@ -19,3 +19,23 @@ async def test_reminders(spa, setup_entry, hass): assert state is not None assert state.state == STATE_OFF assert state.attributes["snoozed"] is False + + +async def test_snooze(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 = 30 + + await hass.services.async_call( + "smarttub", + "snooze_reminder", + { + "entity_id": entity_id, + "days": 30, + }, + blocking=True, + ) + + reminder.snooze.assert_called_with(days)