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 onepull/25291/head
parent
1c6d55e51b
commit
003f7865a9
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/components/simplisafe",
|
||||
"requirements": [
|
||||
"simplisafe-python==4.0.0"
|
||||
"simplisafe-python==4.0.1"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Describes the format for available SimpliSafe services
|
||||
|
||||
---
|
||||
remove_pin:
|
||||
description: Remove a PIN by its label or value.
|
||||
fields:
|
||||
system_id:
|
||||
description: The SimpliSafe system ID to affect.
|
||||
example: 123987
|
||||
label_or_pin:
|
||||
description: The label/value to remove.
|
||||
example: Test PIN
|
||||
set_pin:
|
||||
description: Set/update a PIN
|
||||
fields:
|
||||
system_id:
|
||||
description: The SimpliSafe system ID to affect.
|
||||
example: 123987
|
||||
label:
|
||||
description: The label of the PIN
|
||||
example: Test PIN
|
||||
pin:
|
||||
description: The value of the PIN
|
||||
example: 1256
|
|
@ -1679,7 +1679,7 @@ shodan==1.13.0
|
|||
simplepush==1.1.4
|
||||
|
||||
# homeassistant.components.simplisafe
|
||||
simplisafe-python==4.0.0
|
||||
simplisafe-python==4.0.1
|
||||
|
||||
# homeassistant.components.sisyphus
|
||||
sisyphus-control==2.2
|
||||
|
|
|
@ -334,7 +334,7 @@ ring_doorbell==0.2.3
|
|||
rxv==0.6.0
|
||||
|
||||
# homeassistant.components.simplisafe
|
||||
simplisafe-python==4.0.0
|
||||
simplisafe-python==4.0.1
|
||||
|
||||
# homeassistant.components.sleepiq
|
||||
sleepyq==0.7
|
||||
|
|
Loading…
Reference in New Issue