Add services to set and remove Simplisafe PINs (#25207)
* Add services to set and remove SimpliSafe PINs * Added services spec * Add services to set and remove SimpliSafe PINs * Member comments * Missed one
This commit is contained in:
1 parent
1c6d55e51b
commit
003f7865a9
5 files changed
+65
-3
No files matched your search
@@ -13,6 +13,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.service import verify_domain_control
|
||||
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
@@ -21,10 +22,26 @@ from .const import DATA_CLIENT, DEFAULT_SCAN_INTERVAL, DOMAIN, TOPIC_UPDATE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_PIN_LABEL = 'label'
|
||||
ATTR_PIN_LABEL_OR_VALUE = 'label_or_pin'
|
||||
ATTR_PIN_VALUE = 'pin'
|
||||
ATTR_SYSTEM_ID = 'system_id'
|
||||
|
||||
CONF_ACCOUNTS = 'accounts'
|
||||
|
||||
DATA_LISTENER = 'listener'
|
||||
|
||||
SERVICE_REMOVE_PIN_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_SYSTEM_ID): cv.string,
|
||||
vol.Required(ATTR_PIN_LABEL_OR_VALUE): cv.string,
|
||||
})
|
||||
|
||||
SERVICE_SET_PIN_SCHEMA = vol.Schema({
|
||||
vol.Required(ATTR_SYSTEM_ID): cv.string,
|
||||
vol.Required(ATTR_PIN_LABEL): cv.string,
|
||||
vol.Required(ATTR_PIN_VALUE): cv.string,
|
||||
})
|
||||
|
||||
ACCOUNT_CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
@@ -97,6 +114,8 @@ async def async_setup_entry(hass, config_entry):
|
||||
from simplipy import API
|
||||
from simplipy.errors import InvalidCredentialsError, SimplipyError
|
||||
|
||||
_verify_domain_control = verify_domain_control(hass, DOMAIN)
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(hass)
|
||||
|
||||
try:
|
||||
@@ -149,6 +168,25 @@ async def async_setup_entry(hass, config_entry):
|
||||
async_register_base_station(
|
||||
hass, system, config_entry.entry_id))
|
||||
|
||||
@_verify_domain_control
|
||||
async def remove_pin(call):
|
||||
"""Remove a PIN."""
|
||||
system = systems[int(call.data[ATTR_SYSTEM_ID])]
|
||||
await system.remove_pin(call.data[ATTR_PIN_LABEL_OR_VALUE])
|
||||
|
||||
@_verify_domain_control
|
||||
async def set_pin(call):
|
||||
"""Set a PIN."""
|
||||
system = systems[int(call.data[ATTR_SYSTEM_ID])]
|
||||
await system.set_pin(
|
||||
call.data[ATTR_PIN_LABEL], call.data[ATTR_PIN_VALUE])
|
||||
|
||||
for service, method, schema in [
|
||||
('remove_pin', remove_pin, SERVICE_REMOVE_PIN_SCHEMA),
|
||||
('set_pin', set_pin, SERVICE_SET_PIN_SCHEMA),
|
||||
]:
|
||||
hass.services.async_register(DOMAIN, service, method, schema=schema)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user