mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Simplify blink service actions (#146508)
This commit is contained in:
parent
0af41d9cb1
commit
9346f8d658
@ -25,7 +25,7 @@ from homeassistant.helpers.typing import ConfigType
|
|||||||
|
|
||||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, PLATFORMS
|
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, PLATFORMS
|
||||||
from .coordinator import BlinkConfigEntry, BlinkUpdateCoordinator
|
from .coordinator import BlinkConfigEntry, BlinkUpdateCoordinator
|
||||||
from .services import setup_services
|
from .services import async_setup_services
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ async def async_migrate_entry(hass: HomeAssistant, entry: BlinkConfigEntry) -> b
|
|||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up Blink."""
|
"""Set up Blink."""
|
||||||
|
|
||||||
setup_services(hass)
|
async_setup_services(hass)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import CONF_PIN
|
from homeassistant.const import CONF_PIN
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
@ -21,34 +21,36 @@ SERVICE_SEND_PIN_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup_services(hass: HomeAssistant) -> None:
|
async def _send_pin(call: ServiceCall) -> None:
|
||||||
"""Set up the services for the Blink integration."""
|
"""Call blink to send new pin."""
|
||||||
|
config_entry: BlinkConfigEntry | None
|
||||||
async def send_pin(call: ServiceCall):
|
for entry_id in call.data[ATTR_CONFIG_ENTRY_ID]:
|
||||||
"""Call blink to send new pin."""
|
if not (config_entry := call.hass.config_entries.async_get_entry(entry_id)):
|
||||||
config_entry: BlinkConfigEntry | None
|
raise ServiceValidationError(
|
||||||
for entry_id in call.data[ATTR_CONFIG_ENTRY_ID]:
|
translation_domain=DOMAIN,
|
||||||
if not (config_entry := hass.config_entries.async_get_entry(entry_id)):
|
translation_key="integration_not_found",
|
||||||
raise ServiceValidationError(
|
translation_placeholders={"target": DOMAIN},
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="integration_not_found",
|
|
||||||
translation_placeholders={"target": DOMAIN},
|
|
||||||
)
|
|
||||||
if config_entry.state != ConfigEntryState.LOADED:
|
|
||||||
raise HomeAssistantError(
|
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="not_loaded",
|
|
||||||
translation_placeholders={"target": config_entry.title},
|
|
||||||
)
|
|
||||||
coordinator = config_entry.runtime_data
|
|
||||||
await coordinator.api.auth.send_auth_key(
|
|
||||||
coordinator.api,
|
|
||||||
call.data[CONF_PIN],
|
|
||||||
)
|
)
|
||||||
|
if config_entry.state != ConfigEntryState.LOADED:
|
||||||
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="not_loaded",
|
||||||
|
translation_placeholders={"target": config_entry.title},
|
||||||
|
)
|
||||||
|
coordinator = config_entry.runtime_data
|
||||||
|
await coordinator.api.auth.send_auth_key(
|
||||||
|
coordinator.api,
|
||||||
|
call.data[CONF_PIN],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
|
"""Set up the services for the Blink integration."""
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_SEND_PIN,
|
SERVICE_SEND_PIN,
|
||||||
send_pin,
|
_send_pin,
|
||||||
schema=SERVICE_SEND_PIN_SCHEMA,
|
schema=SERVICE_SEND_PIN_SCHEMA,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user