mirror of
https://github.com/home-assistant/core.git
synced 2026-04-27 12:14:35 +01:00
Add translated action exceptions to Airgradient (#136322)
* Add translated action exceptions to Airgradient * Add translated action exceptions to Airgradient
This commit is contained in:
committed by
GitHub
parent
d6f6961674
commit
40ed0562bc
@@ -3,14 +3,16 @@
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from airgradient import Config
|
||||
from airgradient import AirGradientConnectionError, AirGradientError, Config
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.airgradient.const import DOMAIN
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
@@ -97,3 +99,37 @@ async def test_cloud_creates_no_button(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "error_message"),
|
||||
[
|
||||
(
|
||||
AirGradientConnectionError("Something happened"),
|
||||
"An error occurred while communicating with the Airgradient device: Something happened",
|
||||
),
|
||||
(
|
||||
AirGradientError("Something else happened"),
|
||||
"An unknown error occurred while communicating with the Airgradient device: Something else happened",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_exception_handling(
|
||||
hass: HomeAssistant,
|
||||
mock_airgradient_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
exception: Exception,
|
||||
error_message: str,
|
||||
) -> None:
|
||||
"""Test exception handling."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
mock_airgradient_client.request_co2_calibration.side_effect = exception
|
||||
with pytest.raises(HomeAssistantError, match=error_message):
|
||||
await hass.services.async_call(
|
||||
BUTTON_DOMAIN,
|
||||
SERVICE_PRESS,
|
||||
{
|
||||
ATTR_ENTITY_ID: "button.airgradient_calibrate_co2_sensor",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user