Add Home Connect binary_sensor unit tests (#115323)

This commit is contained in:
Robert Contreras 2024-06-21 08:37:22 -07:00 committed by GitHub
parent 2770811dda
commit 842763bd27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 1 deletions

View File

@ -536,7 +536,6 @@ omit =
homeassistant/components/hko/weather.py
homeassistant/components/hlk_sw16/__init__.py
homeassistant/components/hlk_sw16/switch.py
homeassistant/components/home_connect/binary_sensor.py
homeassistant/components/home_connect/entity.py
homeassistant/components/home_connect/light.py
homeassistant/components/home_connect/switch.py

View File

@ -0,0 +1,74 @@
"""Tests for home_connect binary_sensor entities."""
from collections.abc import Awaitable, Callable, Generator
from typing import Any
from unittest.mock import MagicMock, Mock
import pytest
from homeassistant.components.home_connect.const import (
BSH_DOOR_STATE,
BSH_DOOR_STATE_CLOSED,
BSH_DOOR_STATE_LOCKED,
BSH_DOOR_STATE_OPEN,
)
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_component import async_update_entity
from tests.common import MockConfigEntry
@pytest.fixture
def platforms() -> list[str]:
"""Fixture to specify platforms to test."""
return [Platform.BINARY_SENSOR]
async def test_binary_sensors(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
setup_credentials: None,
get_appliances: MagicMock,
appliance: Mock,
) -> None:
"""Test binary sensor entities."""
get_appliances.return_value = [appliance]
assert config_entry.state == ConfigEntryState.NOT_LOADED
assert await integration_setup()
assert config_entry.state == ConfigEntryState.LOADED
@pytest.mark.parametrize(
("state", "expected"),
[
(BSH_DOOR_STATE_CLOSED, "off"),
(BSH_DOOR_STATE_LOCKED, "off"),
(BSH_DOOR_STATE_OPEN, "on"),
("", "unavailable"),
],
)
async def test_binary_sensors_door_states(
expected: str,
state: str,
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],
setup_credentials: None,
get_appliances: MagicMock,
appliance: Mock,
) -> None:
"""Tests for Appliance door states."""
entity_id = "binary_sensor.washer_door"
get_appliances.return_value = [appliance]
assert config_entry.state == ConfigEntryState.NOT_LOADED
assert await integration_setup()
assert config_entry.state == ConfigEntryState.LOADED
appliance.status.update({BSH_DOOR_STATE: {"value": state}})
await async_update_entity(hass, entity_id)
await hass.async_block_till_done()
assert hass.states.is_state(entity_id, expected)

View File

@ -118,6 +118,7 @@ SERVICE_APPLIANCE_METHOD_MAPPING = {
async def test_api_setup(
bypass_throttle: Generator[None, Any, None],
hass: HomeAssistant,
config_entry: MockConfigEntry,
integration_setup: Callable[[], Awaitable[bool]],