mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Add service to snooze SmartTub reminders (#51012)
* Add service to snooze SmartTub reminders * minimum is 10 days * 0->10 in services.yaml as well * Update homeassistant/components/smarttub/services.yaml Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Update homeassistant/components/smarttub/services.yaml Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
9bf6ea60db
commit
aa18ad2abf
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user