mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Complete tests for eheimdigital (#143337)
* Complete tests for eheimdigital * Review * Review * Review * Review * Fix tests
This commit is contained in:
parent
afb247c907
commit
088c02d38a
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from eheimdigital.types import EheimDeviceType
|
from eheimdigital.types import EheimDeviceType, EheimDigitalClientError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -54,3 +55,15 @@ async def test_remove_device(
|
|||||||
device_entry.id, mock_config_entry.entry_id
|
device_entry.id, mock_config_entry.entry_id
|
||||||
)
|
)
|
||||||
assert response["success"]
|
assert response["success"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_entry_setup_error(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
eheimdigital_hub_mock: MagicMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test errors on setting up the config entry."""
|
||||||
|
|
||||||
|
eheimdigital_hub_mock.return_value.connect.side_effect = EheimDigitalClientError()
|
||||||
|
await init_integration(hass, mock_config_entry)
|
||||||
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
|||||||
|
|
||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
from eheimdigital.classic_led_ctrl import EheimDigitalClassicLEDControl
|
from eheimdigital.classic_led_ctrl import EheimDigitalClassicLEDControl
|
||||||
from eheimdigital.types import EheimDeviceType
|
from eheimdigital.types import EheimDeviceType, EheimDigitalClientError
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
@ -24,6 +24,7 @@ from homeassistant.const import (
|
|||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.util.color import value_to_brightness
|
from homeassistant.util.color import value_to_brightness
|
||||||
|
|
||||||
@ -114,20 +115,34 @@ async def test_dynamic_new_devices(
|
|||||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("eheimdigital_hub_mock")
|
|
||||||
async def test_turn_off(
|
async def test_turn_off(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
|
eheimdigital_hub_mock: MagicMock,
|
||||||
classic_led_ctrl_mock: EheimDigitalClassicLEDControl,
|
classic_led_ctrl_mock: EheimDigitalClassicLEDControl,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test turning off the light."""
|
"""Test turning off the light."""
|
||||||
await init_integration(hass, mock_config_entry)
|
await init_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
await mock_config_entry.runtime_data._async_device_found(
|
await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"](
|
||||||
"00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E
|
"00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
classic_led_ctrl_mock.hub.send_packet.side_effect = EheimDigitalClientError
|
||||||
|
|
||||||
|
with pytest.raises(HomeAssistantError) as exc_info:
|
||||||
|
await hass.services.async_call(
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
SERVICE_TURN_OFF,
|
||||||
|
{ATTR_ENTITY_ID: "light.mock_classicledcontrol_e_channel_1"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exc_info.value.translation_key == "communication_error"
|
||||||
|
|
||||||
|
classic_led_ctrl_mock.hub.send_packet.side_effect = None
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
@ -140,9 +155,9 @@ async def test_turn_off(
|
|||||||
for call in classic_led_ctrl_mock.hub.mock_calls
|
for call in classic_led_ctrl_mock.hub.mock_calls
|
||||||
if call[0] == "send_packet"
|
if call[0] == "send_packet"
|
||||||
]
|
]
|
||||||
assert len(calls) == 2
|
assert len(calls) == 3
|
||||||
assert calls[0][1][0].get("title") == "MAN_MODE"
|
assert calls[1][1][0].get("title") == "MAN_MODE"
|
||||||
assert calls[1][1][0]["currentValues"][1] == 0
|
assert calls[2][1][0]["currentValues"][1] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -169,6 +184,23 @@ async def test_turn_on_brightness(
|
|||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
classic_led_ctrl_mock.hub.send_packet.side_effect = EheimDigitalClientError
|
||||||
|
|
||||||
|
with pytest.raises(HomeAssistantError) as exc_info:
|
||||||
|
await hass.services.async_call(
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
SERVICE_TURN_ON,
|
||||||
|
{
|
||||||
|
ATTR_ENTITY_ID: "light.mock_classicledcontrol_e_channel_1",
|
||||||
|
ATTR_BRIGHTNESS: dim_input,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exc_info.value.translation_key == "communication_error"
|
||||||
|
|
||||||
|
classic_led_ctrl_mock.hub.send_packet.side_effect = None
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
@ -184,9 +216,9 @@ async def test_turn_on_brightness(
|
|||||||
for call in classic_led_ctrl_mock.hub.mock_calls
|
for call in classic_led_ctrl_mock.hub.mock_calls
|
||||||
if call[0] == "send_packet"
|
if call[0] == "send_packet"
|
||||||
]
|
]
|
||||||
assert len(calls) == 2
|
assert len(calls) == 3
|
||||||
assert calls[0][1][0].get("title") == "MAN_MODE"
|
assert calls[1][1][0].get("title") == "MAN_MODE"
|
||||||
assert calls[1][1][0]["currentValues"][1] == expected_dim_value
|
assert calls[2][1][0]["currentValues"][1] == expected_dim_value
|
||||||
|
|
||||||
|
|
||||||
async def test_turn_on_effect(
|
async def test_turn_on_effect(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user