diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index d2234fb308e..48c68f49a3d 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -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 diff --git a/homeassistant/components/simplisafe/manifest.json b/homeassistant/components/simplisafe/manifest.json index 702ab984677..095de440ab6 100644 --- a/homeassistant/components/simplisafe/manifest.json +++ b/homeassistant/components/simplisafe/manifest.json @@ -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": [ diff --git a/homeassistant/components/simplisafe/services.yaml b/homeassistant/components/simplisafe/services.yaml new file mode 100644 index 00000000000..52e66a435c6 --- /dev/null +++ b/homeassistant/components/simplisafe/services.yaml @@ -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 diff --git a/requirements_all.txt b/requirements_all.txt index 307bd0f51a8..7e2815a7479 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 052d4f0c1f8..2fc933e4080 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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