diff --git a/homeassistant/components/blink/__init__.py b/homeassistant/components/blink/__init__.py index 534fff310e3..e57b8e52729 100644 --- a/homeassistant/components/blink/__init__.py +++ b/homeassistant/components/blink/__init__.py @@ -87,12 +87,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: await blink.start() - if blink.auth.check_key_required(): - _LOGGER.debug("Attempting a reauth flow") - raise ConfigEntryAuthFailed("Need 2FA for Blink") except (ClientError, asyncio.TimeoutError) as ex: raise ConfigEntryNotReady("Can not connect to host") from ex + if blink.auth.check_key_required(): + _LOGGER.debug("Attempting a reauth flow") + raise ConfigEntryAuthFailed("Need 2FA for Blink") + hass.data[DOMAIN][entry.entry_id] = blink if not blink.available: diff --git a/homeassistant/components/blink/alarm_control_panel.py b/homeassistant/components/blink/alarm_control_panel.py index b69f9b84670..2249c9bf16f 100644 --- a/homeassistant/components/blink/alarm_control_panel.py +++ b/homeassistant/components/blink/alarm_control_panel.py @@ -91,15 +91,17 @@ class BlinkSyncModuleHA(AlarmControlPanelEntity): try: await self.sync.async_arm(False) await self.sync.refresh(force=True) - self.async_write_ha_state() except asyncio.TimeoutError: self._attr_available = False + self.async_write_ha_state() + async def async_alarm_arm_away(self, code: str | None = None) -> None: """Send arm command.""" try: await self.sync.async_arm(True) await self.sync.refresh(force=True) - self.async_write_ha_state() except asyncio.TimeoutError: self._attr_available = False + + self.async_write_ha_state() diff --git a/homeassistant/components/blink/binary_sensor.py b/homeassistant/components/blink/binary_sensor.py index 1edb8b91336..51df22dbf0e 100644 --- a/homeassistant/components/blink/binary_sensor.py +++ b/homeassistant/components/blink/binary_sensor.py @@ -52,7 +52,7 @@ async def async_setup_entry( for camera in data.cameras for description in BINARY_SENSORS_TYPES ] - async_add_entities(entities, update_before_add=True) + async_add_entities(entities) class BlinkBinarySensor(BinarySensorEntity): diff --git a/homeassistant/components/blink/camera.py b/homeassistant/components/blink/camera.py index 1a28d52356e..bf7af4fe619 100644 --- a/homeassistant/components/blink/camera.py +++ b/homeassistant/components/blink/camera.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio from collections.abc import Mapping +import contextlib import logging from typing import Any @@ -32,7 +33,7 @@ async def async_setup_entry( BlinkCamera(data, name, camera) for name, camera in data.cameras.items() ] - async_add_entities(entities, update_before_add=True) + async_add_entities(entities) platform = entity_platform.async_get_current_platform() platform.async_register_entity_service(SERVICE_TRIGGER, {}, "trigger_camera") @@ -44,7 +45,7 @@ class BlinkCamera(Camera): _attr_has_entity_name = True _attr_name = None - def __init__(self, data, name, camera): + def __init__(self, data, name, camera) -> None: """Initialize a camera.""" super().__init__() self.data = data @@ -91,11 +92,9 @@ class BlinkCamera(Camera): async def trigger_camera(self) -> None: """Trigger camera to take a snapshot.""" - try: + with contextlib.suppress(asyncio.TimeoutError): await self._camera.snap_picture() - self.async_schedule_update_ha_state(force_refresh=True) - except asyncio.TimeoutError: - pass + self.async_write_ha_state() def camera_image( self, width: int | None = None, height: int | None = None diff --git a/homeassistant/components/blink/config_flow.py b/homeassistant/components/blink/config_flow.py index cc740d8be31..4326c6cb86c 100644 --- a/homeassistant/components/blink/config_flow.py +++ b/homeassistant/components/blink/config_flow.py @@ -60,7 +60,7 @@ async def validate_input(auth: Auth) -> None: raise Require2FA -async def _send_blink_2fa_pin(hass: HomeAssistant, auth: Auth, pin: str) -> bool: +async def _send_blink_2fa_pin(hass: HomeAssistant, auth: Auth, pin: str | None) -> bool: """Send 2FA pin to blink servers.""" blink = Blink(session=async_get_clientsession(hass)) blink.auth = auth @@ -127,9 +127,10 @@ class BlinkConfigFlow(ConfigFlow, domain=DOMAIN): """Handle 2FA step.""" errors = {} if user_input is not None: - pin: str = str(user_input.get(CONF_PIN)) try: - valid_token = await _send_blink_2fa_pin(self.hass, self.auth, pin) + valid_token = await _send_blink_2fa_pin( + self.hass, self.auth, user_input.get(CONF_PIN) + ) except BlinkSetupError: errors["base"] = "cannot_connect" except Exception: # pylint: disable=broad-except diff --git a/homeassistant/components/blink/sensor.py b/homeassistant/components/blink/sensor.py index e4fdabc29d1..c979c9b6a53 100644 --- a/homeassistant/components/blink/sensor.py +++ b/homeassistant/components/blink/sensor.py @@ -56,7 +56,7 @@ async def async_setup_entry( for description in SENSOR_TYPES ] - async_add_entities(entities, update_before_add=True) + async_add_entities(entities) class BlinkSensor(SensorEntity): diff --git a/tests/components/blink/test_config_flow.py b/tests/components/blink/test_config_flow.py index 0809a674600..ab04499c827 100644 --- a/tests/components/blink/test_config_flow.py +++ b/tests/components/blink/test_config_flow.py @@ -271,7 +271,7 @@ async def test_options_flow(hass: HomeAssistant) -> None: mock_auth = AsyncMock( startup=Mock(return_value=True), check_key_required=Mock(return_value=False) ) - mock_blink = AsyncMock() + mock_blink = AsyncMock(cameras=Mock(), sync=Mock()) with patch("homeassistant.components.blink.Auth", return_value=mock_auth), patch( "homeassistant.components.blink.Blink", return_value=mock_blink