|
6 | 6 |
|
7 | 7 | from homeassistant.config_entries import ConfigEntryState |
8 | 8 | from homeassistant.const import CONF_PIN |
9 | | -from homeassistant.core import HomeAssistant, ServiceCall |
| 9 | +from homeassistant.core import HomeAssistant, ServiceCall, callback |
10 | 10 | from homeassistant.exceptions import HomeAssistantError, ServiceValidationError |
11 | 11 | from homeassistant.helpers import config_validation as cv |
12 | 12 |
|
|
21 | 21 | ) |
22 | 22 |
|
23 | 23 |
|
24 | | -def setup_services(hass: HomeAssistant) -> None: |
25 | | - """Set up the services for the Blink integration.""" |
26 | | - |
27 | | - async def send_pin(call: ServiceCall): |
28 | | - """Call blink to send new pin.""" |
29 | | - config_entry: BlinkConfigEntry | None |
30 | | - for entry_id in call.data[ATTR_CONFIG_ENTRY_ID]: |
31 | | - if not (config_entry := hass.config_entries.async_get_entry(entry_id)): |
32 | | - raise ServiceValidationError( |
33 | | - translation_domain=DOMAIN, |
34 | | - translation_key="integration_not_found", |
35 | | - translation_placeholders={"target": DOMAIN}, |
36 | | - ) |
37 | | - if config_entry.state != ConfigEntryState.LOADED: |
38 | | - raise HomeAssistantError( |
39 | | - translation_domain=DOMAIN, |
40 | | - translation_key="not_loaded", |
41 | | - translation_placeholders={"target": config_entry.title}, |
42 | | - ) |
43 | | - coordinator = config_entry.runtime_data |
44 | | - await coordinator.api.auth.send_auth_key( |
45 | | - coordinator.api, |
46 | | - call.data[CONF_PIN], |
| 24 | +async def _send_pin(call: ServiceCall) -> None: |
| 25 | + """Call blink to send new pin.""" |
| 26 | + config_entry: BlinkConfigEntry | None |
| 27 | + for entry_id in call.data[ATTR_CONFIG_ENTRY_ID]: |
| 28 | + if not (config_entry := call.hass.config_entries.async_get_entry(entry_id)): |
| 29 | + raise ServiceValidationError( |
| 30 | + translation_domain=DOMAIN, |
| 31 | + translation_key="integration_not_found", |
| 32 | + translation_placeholders={"target": DOMAIN}, |
| 33 | + ) |
| 34 | + if config_entry.state != ConfigEntryState.LOADED: |
| 35 | + raise HomeAssistantError( |
| 36 | + translation_domain=DOMAIN, |
| 37 | + translation_key="not_loaded", |
| 38 | + translation_placeholders={"target": config_entry.title}, |
47 | 39 | ) |
| 40 | + coordinator = config_entry.runtime_data |
| 41 | + await coordinator.api.auth.send_auth_key( |
| 42 | + coordinator.api, |
| 43 | + call.data[CONF_PIN], |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +@callback |
| 48 | +def async_setup_services(hass: HomeAssistant) -> None: |
| 49 | + """Set up the services for the Blink integration.""" |
48 | 50 |
|
49 | 51 | hass.services.async_register( |
50 | 52 | DOMAIN, |
51 | 53 | SERVICE_SEND_PIN, |
52 | | - send_pin, |
| 54 | + _send_pin, |
53 | 55 | schema=SERVICE_SEND_PIN_SCHEMA, |
54 | 56 | ) |
0 commit comments