Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions homeassistant/components/smarttub/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,6 +19,12 @@
# 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."""
Expand All @@ -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)."""
Expand Down Expand Up @@ -98,3 +114,9 @@ def extra_state_attributes(self):
def device_class(self) -> str:
"""Return the device class for this entity."""
return DEVICE_CLASS_PROBLEM

async def async_snooze(self, **kwargs):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to accept kwargs here. We can just name the parameter the same as the service data attribute, ie days.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""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()
19 changes: 19 additions & 0 deletions homeassistant/components/smarttub/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions tests/components/smarttub/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)