mirror of
https://github.com/home-assistant/core
synced 2024-10-04 21:12:37 +00:00
Improve type annotation in Shelly tests (#110361)
Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
1a22189262
commit
8de038527f
|
@ -1,6 +1,4 @@
|
|||
"""Tests for the Shelly integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from copy import deepcopy
|
||||
from datetime import timedelta
|
||||
|
@ -21,7 +19,11 @@ from homeassistant.components.shelly.const import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, format_mac
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
DeviceRegistry,
|
||||
format_mac,
|
||||
)
|
||||
from homeassistant.helpers.entity_registry import async_get
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
@ -85,14 +87,16 @@ async def mock_rest_update(
|
|||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
seconds=REST_SENSORS_UPDATE_INTERVAL,
|
||||
):
|
||||
) -> None:
|
||||
"""Move time to create REST sensors update event."""
|
||||
freezer.tick(timedelta(seconds=seconds))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def mock_polling_rpc_update(hass: HomeAssistant, freezer: FrozenDateTimeFactory):
|
||||
async def mock_polling_rpc_update(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Move time to create polling RPC sensors update event."""
|
||||
freezer.tick(timedelta(seconds=RPC_SENSORS_POLLING_INTERVAL))
|
||||
async_fire_time_changed(hass)
|
||||
|
@ -128,7 +132,7 @@ def get_entity_state(hass: HomeAssistant, entity_id: str) -> str:
|
|||
return entity.state
|
||||
|
||||
|
||||
def register_device(device_reg, config_entry: ConfigEntry):
|
||||
def register_device(device_reg: DeviceRegistry, config_entry: ConfigEntry) -> None:
|
||||
"""Register Shelly device."""
|
||||
device_reg.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
"""Test configuration for Shelly."""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, Mock, PropertyMock, patch
|
||||
|
||||
from aioshelly.block_device import BlockDevice, BlockUpdateType
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
"""Tests for Shelly binary sensor platform."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from aioshelly.const import MODEL_MOTION
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.shelly.const import SLEEP_PERIOD_MULTIPLIER
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import (
|
||||
init_integration,
|
||||
|
@ -22,7 +27,10 @@ SENSOR_BLOCK_ID = 3
|
|||
|
||||
|
||||
async def test_block_binary_sensor(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block binary sensor."""
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_channel_1_overpowering"
|
||||
|
@ -41,7 +49,10 @@ async def test_block_binary_sensor(
|
|||
|
||||
|
||||
async def test_block_binary_sensor_extra_state_attr(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block binary sensor extra state attributes."""
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_gas"
|
||||
|
@ -66,9 +77,9 @@ async def test_block_binary_sensor_extra_state_attr(
|
|||
async def test_block_rest_binary_sensor(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
entity_registry,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block REST binary sensor."""
|
||||
entity_id = register_entity(hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud")
|
||||
|
@ -90,9 +101,9 @@ async def test_block_rest_binary_sensor(
|
|||
async def test_block_rest_binary_sensor_connected_battery_devices(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
entity_registry,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block REST binary sensor for connected battery devices."""
|
||||
entity_id = register_entity(hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud")
|
||||
|
@ -119,7 +130,10 @@ async def test_block_rest_binary_sensor_connected_battery_devices(
|
|||
|
||||
|
||||
async def test_block_sleeping_binary_sensor(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block sleeping binary sensor."""
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_motion"
|
||||
|
@ -145,7 +159,10 @@ async def test_block_sleeping_binary_sensor(
|
|||
|
||||
|
||||
async def test_block_restored_sleeping_binary_sensor(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored sleeping binary sensor."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -169,7 +186,10 @@ async def test_block_restored_sleeping_binary_sensor(
|
|||
|
||||
|
||||
async def test_block_restored_sleeping_binary_sensor_no_last_state(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored sleeping binary sensor missing last state."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -192,7 +212,10 @@ async def test_block_restored_sleeping_binary_sensor_no_last_state(
|
|||
|
||||
|
||||
async def test_rpc_binary_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test RPC binary sensor."""
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_cover_0_overpowering"
|
||||
|
@ -213,7 +236,10 @@ async def test_rpc_binary_sensor(
|
|||
|
||||
|
||||
async def test_rpc_binary_sensor_removal(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test RPC binary sensor is removed due to removal_condition."""
|
||||
entity_id = register_entity(
|
||||
|
@ -229,16 +255,21 @@ async def test_rpc_binary_sensor_removal(
|
|||
|
||||
|
||||
async def test_rpc_sleeping_binary_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test RPC online sleeping binary sensor."""
|
||||
entity_id = f"{BINARY_SENSOR_DOMAIN}.test_name_cloud"
|
||||
entry = await init_integration(hass, 2, sleep_period=1000)
|
||||
config_entry = await init_integration(hass, 2, sleep_period=1000)
|
||||
|
||||
# Sensor should be created when device is online
|
||||
assert hass.states.get(entity_id) is None
|
||||
|
||||
register_entity(hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud-cloud", entry)
|
||||
register_entity(
|
||||
hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud-cloud", config_entry
|
||||
)
|
||||
|
||||
# Make device online
|
||||
mock_rpc_device.mock_update()
|
||||
|
@ -262,7 +293,10 @@ async def test_rpc_sleeping_binary_sensor(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_binary_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored binary sensor."""
|
||||
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
|
||||
|
@ -288,7 +322,10 @@ async def test_rpc_restored_sleeping_binary_sensor(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_binary_sensor_no_last_state(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored sleeping binary sensor missing last state."""
|
||||
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for Shelly button platform."""
|
||||
from __future__ import annotations
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -7,13 +7,13 @@ from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRE
|
|||
from homeassistant.components.shelly.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration
|
||||
|
||||
|
||||
async def test_block_button(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry
|
||||
hass: HomeAssistant, mock_block_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test block device reboot button."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -37,7 +37,7 @@ async def test_block_button(
|
|||
|
||||
|
||||
async def test_rpc_button(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test rpc device OTA button."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -70,9 +70,9 @@ async def test_rpc_button(
|
|||
)
|
||||
async def test_migrate_unique_id(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
mock_rpc_device,
|
||||
entity_registry,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
gen: int,
|
||||
old_unique_id: str,
|
||||
|
@ -82,7 +82,7 @@ async def test_migrate_unique_id(
|
|||
"""Test migration of unique_id."""
|
||||
entry = await init_integration(hass, gen, skip_setup=True)
|
||||
|
||||
entity: er.RegistryEntry = entity_registry.async_get_or_create(
|
||||
entity = entity_registry.async_get_or_create(
|
||||
suggested_object_id="test_name_reboot",
|
||||
disabled_by=None,
|
||||
domain=BUTTON_DOMAIN,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Tests for Shelly climate platform."""
|
||||
from copy import deepcopy
|
||||
from unittest.mock import AsyncMock, PropertyMock
|
||||
from unittest.mock import AsyncMock, Mock, PropertyMock
|
||||
|
||||
from aioshelly.const import MODEL_VALVE
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
||||
|
@ -26,8 +26,9 @@ from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
|||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
import homeassistant.helpers.issue_registry as ir
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
from homeassistant.helpers.issue_registry import IssueRegistry
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import MOCK_MAC, init_integration, register_device, register_entity
|
||||
|
@ -43,7 +44,10 @@ ENTITY_ID = f"{CLIMATE_DOMAIN}.test_name"
|
|||
|
||||
|
||||
async def test_climate_hvac_mode(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test climate hvac mode service."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -110,7 +114,7 @@ async def test_climate_hvac_mode(
|
|||
|
||||
|
||||
async def test_climate_set_temperature(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test climate set temperature service."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -176,7 +180,7 @@ async def test_climate_set_temperature(
|
|||
|
||||
|
||||
async def test_climate_set_preset_mode(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test climate set preset mode service."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -231,7 +235,10 @@ async def test_climate_set_preset_mode(
|
|||
|
||||
|
||||
async def test_block_restored_climate(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored climate."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -294,7 +301,10 @@ async def test_block_restored_climate(
|
|||
|
||||
|
||||
async def test_block_restored_climate_us_customery(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored climate with US CUSTOMATY unit system."""
|
||||
hass.config.units = US_CUSTOMARY_SYSTEM
|
||||
|
@ -363,7 +373,10 @@ async def test_block_restored_climate_us_customery(
|
|||
|
||||
|
||||
async def test_block_restored_climate_unavailable(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored climate unavailable state."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -387,7 +400,10 @@ async def test_block_restored_climate_unavailable(
|
|||
|
||||
|
||||
async def test_block_restored_climate_set_preset_before_online(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored climate set preset before device is online."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -421,7 +437,7 @@ async def test_block_restored_climate_set_preset_before_online(
|
|||
|
||||
|
||||
async def test_block_set_mode_connection_error(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device set mode connection error."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
||||
|
@ -446,7 +462,7 @@ async def test_block_set_mode_connection_error(
|
|||
|
||||
|
||||
async def test_block_set_mode_auth_error(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device set mode authentication error."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
|
||||
|
@ -486,7 +502,10 @@ async def test_block_set_mode_auth_error(
|
|||
|
||||
|
||||
async def test_block_restored_climate_auth_error(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored climate with authentication error during init."""
|
||||
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
|
||||
|
@ -532,9 +551,9 @@ async def test_block_restored_climate_auth_error(
|
|||
|
||||
async def test_device_not_calibrated(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
issue_registry: IssueRegistry,
|
||||
) -> None:
|
||||
"""Test to create an issue when the device is not calibrated."""
|
||||
await init_integration(hass, 1, sleep_period=1000, model=MODEL_VALVE)
|
||||
|
@ -573,9 +592,9 @@ async def test_device_not_calibrated(
|
|||
|
||||
async def test_rpc_climate_hvac_mode(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
entity_registry: EntityRegistry,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test climate hvac mode service."""
|
||||
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
|
||||
|
@ -613,7 +632,7 @@ async def test_rpc_climate_hvac_mode(
|
|||
|
||||
|
||||
async def test_rpc_climate_set_temperature(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test climate set target temperature."""
|
||||
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
|
||||
|
@ -651,7 +670,7 @@ async def test_rpc_climate_set_temperature(
|
|||
|
||||
|
||||
async def test_rpc_climate_hvac_mode_cool(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test climate with hvac mode cooling."""
|
||||
new_config = deepcopy(mock_rpc_device.config)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
"""Test the Shelly config flow."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import replace
|
||||
from ipaddress import ip_address
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioshelly.const import MODEL_1, MODEL_PLUS_2PM
|
||||
from aioshelly.exceptions import (
|
||||
|
@ -59,7 +58,11 @@ DISCOVERY_INFO_WITH_MAC = zeroconf.ZeroconfServiceInfo(
|
|||
],
|
||||
)
|
||||
async def test_form(
|
||||
hass: HomeAssistant, gen, model, mock_block_device, mock_rpc_device
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
model: str,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -120,12 +123,12 @@ async def test_form(
|
|||
)
|
||||
async def test_form_auth(
|
||||
hass: HomeAssistant,
|
||||
gen,
|
||||
model,
|
||||
user_input,
|
||||
username,
|
||||
mock_block_device,
|
||||
mock_rpc_device,
|
||||
gen: int,
|
||||
model: str,
|
||||
user_input: dict[str, str],
|
||||
username: str,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test manual configuration if auth is required."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -178,7 +181,9 @@ async def test_form_auth(
|
|||
(ValueError, "unknown"),
|
||||
],
|
||||
)
|
||||
async def test_form_errors_get_info(hass: HomeAssistant, exc, base_error) -> None:
|
||||
async def test_form_errors_get_info(
|
||||
hass: HomeAssistant, exc: Exception, base_error: str
|
||||
) -> None:
|
||||
"""Test we handle errors."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
|
@ -195,7 +200,7 @@ async def test_form_errors_get_info(hass: HomeAssistant, exc, base_error) -> Non
|
|||
|
||||
|
||||
async def test_form_missing_model_key(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test we handle missing Shelly model key."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -216,7 +221,7 @@ async def test_form_missing_model_key(
|
|||
|
||||
|
||||
async def test_form_missing_model_key_auth_enabled(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test we handle missing Shelly model key when auth enabled."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -246,7 +251,9 @@ async def test_form_missing_model_key_auth_enabled(
|
|||
|
||||
|
||||
async def test_form_missing_model_key_zeroconf(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test we handle missing Shelly model key via zeroconf."""
|
||||
monkeypatch.setattr(mock_rpc_device, "shelly", {"gen": 2})
|
||||
|
@ -278,7 +285,7 @@ async def test_form_missing_model_key_zeroconf(
|
|||
],
|
||||
)
|
||||
async def test_form_errors_test_connection(
|
||||
hass: HomeAssistant, exc, base_error
|
||||
hass: HomeAssistant, exc: Exception, base_error: str
|
||||
) -> None:
|
||||
"""Test we handle errors."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -329,7 +336,7 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
async def test_user_setup_ignored_device(
|
||||
hass: HomeAssistant, mock_block_device
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test user can successfully setup an ignored device."""
|
||||
|
||||
|
@ -395,7 +402,7 @@ async def test_form_firmware_unsupported(hass: HomeAssistant) -> None:
|
|||
],
|
||||
)
|
||||
async def test_form_auth_errors_test_connection_gen1(
|
||||
hass: HomeAssistant, exc, base_error
|
||||
hass: HomeAssistant, exc: Exception, base_error: str
|
||||
) -> None:
|
||||
"""Test we handle errors in Gen1 authenticated devices."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -432,7 +439,7 @@ async def test_form_auth_errors_test_connection_gen1(
|
|||
],
|
||||
)
|
||||
async def test_form_auth_errors_test_connection_gen2(
|
||||
hass: HomeAssistant, exc, base_error
|
||||
hass: HomeAssistant, exc: Exception, base_error: str
|
||||
) -> None:
|
||||
"""Test we handle errors in Gen2 authenticated devices."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -480,7 +487,12 @@ async def test_form_auth_errors_test_connection_gen2(
|
|||
],
|
||||
)
|
||||
async def test_zeroconf(
|
||||
hass: HomeAssistant, gen, model, get_info, mock_block_device, mock_rpc_device
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
model: str,
|
||||
get_info: dict[str, Any],
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
|
||||
|
@ -526,7 +538,7 @@ async def test_zeroconf(
|
|||
|
||||
|
||||
async def test_zeroconf_sleeping_device(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test sleeping device configuration via zeroconf."""
|
||||
monkeypatch.setitem(
|
||||
|
@ -708,7 +720,9 @@ async def test_zeroconf_cannot_connect(hass: HomeAssistant) -> None:
|
|||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_zeroconf_require_auth(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_zeroconf_require_auth(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test zeroconf if auth is required."""
|
||||
|
||||
with patch(
|
||||
|
@ -758,7 +772,11 @@ async def test_zeroconf_require_auth(hass: HomeAssistant, mock_block_device) ->
|
|||
],
|
||||
)
|
||||
async def test_reauth_successful(
|
||||
hass: HomeAssistant, gen, user_input, mock_block_device, mock_rpc_device
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
user_input: dict[str, str],
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test starting a reauthentication flow."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -796,7 +814,9 @@ async def test_reauth_successful(
|
|||
(3, {"password": "test2 password"}),
|
||||
],
|
||||
)
|
||||
async def test_reauth_unsuccessful(hass: HomeAssistant, gen, user_input) -> None:
|
||||
async def test_reauth_unsuccessful(
|
||||
hass: HomeAssistant, gen: int, user_input: dict[str, str]
|
||||
) -> None:
|
||||
"""Test reauthentication flow failed."""
|
||||
entry = MockConfigEntry(
|
||||
domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": gen}
|
||||
|
@ -835,7 +855,7 @@ async def test_reauth_unsuccessful(hass: HomeAssistant, gen, user_input) -> None
|
|||
"error",
|
||||
[DeviceConnectionError, FirmwareUnsupported],
|
||||
)
|
||||
async def test_reauth_get_info_error(hass: HomeAssistant, error) -> None:
|
||||
async def test_reauth_get_info_error(hass: HomeAssistant, error: Exception) -> None:
|
||||
"""Test reauthentication flow failed with error in get_info()."""
|
||||
entry = MockConfigEntry(
|
||||
domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": 2}
|
||||
|
@ -865,7 +885,7 @@ async def test_reauth_get_info_error(hass: HomeAssistant, error) -> None:
|
|||
|
||||
|
||||
async def test_options_flow_disabled_gen_1(
|
||||
hass: HomeAssistant, mock_block_device, hass_ws_client: WebSocketGenerator
|
||||
hass: HomeAssistant, mock_block_device: Mock, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
"""Test options are disabled for gen1 devices."""
|
||||
await async_setup_component(hass, "config", {})
|
||||
|
@ -886,7 +906,7 @@ async def test_options_flow_disabled_gen_1(
|
|||
|
||||
|
||||
async def test_options_flow_enabled_gen_2(
|
||||
hass: HomeAssistant, mock_rpc_device, hass_ws_client: WebSocketGenerator
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
"""Test options are enabled for gen2 devices."""
|
||||
await async_setup_component(hass, "config", {})
|
||||
|
@ -907,7 +927,7 @@ async def test_options_flow_enabled_gen_2(
|
|||
|
||||
|
||||
async def test_options_flow_disabled_sleepy_gen_2(
|
||||
hass: HomeAssistant, mock_rpc_device, hass_ws_client: WebSocketGenerator
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, hass_ws_client: WebSocketGenerator
|
||||
) -> None:
|
||||
"""Test options are disabled for sleepy gen2 devices."""
|
||||
await async_setup_component(hass, "config", {})
|
||||
|
@ -927,7 +947,7 @@ async def test_options_flow_disabled_sleepy_gen_2(
|
|||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_options_flow_ble(hass: HomeAssistant, mock_rpc_device) -> None:
|
||||
async def test_options_flow_ble(hass: HomeAssistant, mock_rpc_device: Mock) -> None:
|
||||
"""Test setting ble options for gen2 devices."""
|
||||
entry = await init_integration(hass, 2)
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
@ -982,7 +1002,7 @@ async def test_options_flow_ble(hass: HomeAssistant, mock_rpc_device) -> None:
|
|||
|
||||
|
||||
async def test_zeroconf_already_configured_triggers_refresh_mac_in_name(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test zeroconf discovery triggers refresh when the mac is in the device name."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1014,7 +1034,7 @@ async def test_zeroconf_already_configured_triggers_refresh_mac_in_name(
|
|||
|
||||
|
||||
async def test_zeroconf_already_configured_triggers_refresh(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test zeroconf discovery triggers refresh when the mac is obtained via get_info."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1046,7 +1066,10 @@ async def test_zeroconf_already_configured_triggers_refresh(
|
|||
|
||||
|
||||
async def test_zeroconf_sleeping_device_not_triggers_refresh(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test zeroconf discovery does not triggers refresh for sleeping device."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1082,7 +1105,7 @@ async def test_zeroconf_sleeping_device_not_triggers_refresh(
|
|||
|
||||
|
||||
async def test_sleeping_device_gen2_with_new_firmware(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test sleeping device Gen2 with firmware 1.0.0 or later."""
|
||||
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 666)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Tests for Shelly coordinator."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioshelly.const import MODEL_BULB, MODEL_BUTTON1
|
||||
from aioshelly.exceptions import (
|
||||
|
@ -9,6 +9,7 @@ from aioshelly.exceptions import (
|
|||
InvalidAuthError,
|
||||
)
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
|
@ -26,7 +27,7 @@ from homeassistant.components.shelly.const import (
|
|||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_DEVICE_ID, STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
async_entries_for_config_entry,
|
||||
|
@ -54,7 +55,10 @@ DEVICE_BLOCK_ID = 4
|
|||
|
||||
|
||||
async def test_block_reload_on_cfg_change(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block reload on config change."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -82,7 +86,10 @@ async def test_block_reload_on_cfg_change(
|
|||
|
||||
|
||||
async def test_block_no_reload_on_bulb_changes(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block no reload on bulb mode/effect change."""
|
||||
await init_integration(hass, 1, model=MODEL_BULB)
|
||||
|
@ -126,7 +133,10 @@ async def test_block_no_reload_on_bulb_changes(
|
|||
|
||||
|
||||
async def test_block_polling_auth_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device polling authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -158,7 +168,10 @@ async def test_block_polling_auth_error(
|
|||
|
||||
|
||||
async def test_block_rest_update_auth_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block REST update authentication error."""
|
||||
register_entity(hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud")
|
||||
|
@ -191,7 +204,10 @@ async def test_block_rest_update_auth_error(
|
|||
|
||||
|
||||
async def test_block_firmware_unsupported(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device polling authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -212,7 +228,10 @@ async def test_block_firmware_unsupported(
|
|||
|
||||
|
||||
async def test_block_polling_connection_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device polling connection error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -233,7 +252,10 @@ async def test_block_polling_connection_error(
|
|||
|
||||
|
||||
async def test_block_rest_update_connection_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block REST update connection error."""
|
||||
entity_id = register_entity(hass, BINARY_SENSOR_DOMAIN, "test_name_cloud", "cloud")
|
||||
|
@ -255,7 +277,7 @@ async def test_block_rest_update_connection_error(
|
|||
|
||||
|
||||
async def test_block_sleeping_device_no_periodic_updates(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test block sleeping device no periodic updates."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_temperature"
|
||||
|
@ -277,8 +299,7 @@ async def test_block_sleeping_device_no_periodic_updates(
|
|||
|
||||
async def test_block_device_push_updates_failure(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test block device with push updates failure."""
|
||||
|
@ -303,7 +324,10 @@ async def test_block_device_push_updates_failure(
|
|||
|
||||
|
||||
async def test_block_button_click_event(
|
||||
hass: HomeAssistant, mock_block_device, events, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
events: list[Event],
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block click event for Shelly button."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[RELAY_BLOCK_ID], "sensor_ids", {})
|
||||
|
@ -346,7 +370,10 @@ async def test_block_button_click_event(
|
|||
|
||||
|
||||
async def test_rpc_reload_on_cfg_change(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC reload on config change."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -388,7 +415,10 @@ async def test_rpc_reload_on_cfg_change(
|
|||
|
||||
|
||||
async def test_rpc_reload_with_invalid_auth(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC when InvalidAuthError is raising during config entry reload."""
|
||||
with patch(
|
||||
|
@ -440,7 +470,10 @@ async def test_rpc_reload_with_invalid_auth(
|
|||
|
||||
|
||||
async def test_rpc_click_event(
|
||||
hass: HomeAssistant, mock_rpc_device, events, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
events: list[Event],
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC click event."""
|
||||
entry = await init_integration(hass, 2)
|
||||
|
@ -477,7 +510,10 @@ async def test_rpc_click_event(
|
|||
|
||||
|
||||
async def test_rpc_update_entry_sleep_period(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC update entry sleep period."""
|
||||
entry = await init_integration(hass, 2, sleep_period=600)
|
||||
|
@ -505,7 +541,7 @@ async def test_rpc_update_entry_sleep_period(
|
|||
|
||||
|
||||
async def test_rpc_sleeping_device_no_periodic_updates(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test RPC sleeping device no periodic updates."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_temperature"
|
||||
|
@ -533,7 +569,7 @@ async def test_rpc_sleeping_device_no_periodic_updates(
|
|||
|
||||
|
||||
async def test_rpc_firmware_unsupported(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test RPC update entry unsupported firmware."""
|
||||
entry = await init_integration(hass, 2)
|
||||
|
@ -554,7 +590,10 @@ async def test_rpc_firmware_unsupported(
|
|||
|
||||
|
||||
async def test_rpc_reconnect_auth_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC reconnect authentication error."""
|
||||
entry = await init_integration(hass, 2)
|
||||
|
@ -590,7 +629,10 @@ async def test_rpc_reconnect_auth_error(
|
|||
|
||||
|
||||
async def test_rpc_polling_auth_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC polling authentication error."""
|
||||
register_entity(hass, SENSOR_DOMAIN, "test_name_rssi", "wifi-rssi")
|
||||
|
@ -623,7 +665,10 @@ async def test_rpc_polling_auth_error(
|
|||
|
||||
|
||||
async def test_rpc_reconnect_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC reconnect error."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -648,7 +693,10 @@ async def test_rpc_reconnect_error(
|
|||
|
||||
|
||||
async def test_rpc_polling_connection_error(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC polling connection error."""
|
||||
entity_id = register_entity(hass, SENSOR_DOMAIN, "test_name_rssi", "wifi-rssi")
|
||||
|
@ -670,7 +718,10 @@ async def test_rpc_polling_connection_error(
|
|||
|
||||
|
||||
async def test_rpc_polling_disconnected(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC polling device disconnected."""
|
||||
entity_id = register_entity(hass, SENSOR_DOMAIN, "test_name_rssi", "wifi-rssi")
|
||||
|
@ -686,7 +737,7 @@ async def test_rpc_polling_disconnected(
|
|||
|
||||
|
||||
async def test_rpc_update_entry_fw_ver(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test RPC update entry firmware version."""
|
||||
entry = await init_integration(hass, 2, sleep_period=600)
|
||||
|
|
|
@ -18,6 +18,7 @@ from homeassistant.components.cover import (
|
|||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, mutate_rpc_device_status
|
||||
|
||||
|
@ -25,7 +26,10 @@ ROLLER_BLOCK_ID = 1
|
|||
|
||||
|
||||
async def test_block_device_services(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, entity_registry
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block device cover services."""
|
||||
entity_id = "cover.test_name"
|
||||
|
@ -71,7 +75,7 @@ async def test_block_device_services(
|
|||
|
||||
|
||||
async def test_block_device_update(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device update."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[ROLLER_BLOCK_ID], "rollerPos", 0)
|
||||
|
@ -85,7 +89,7 @@ async def test_block_device_update(
|
|||
|
||||
|
||||
async def test_block_device_no_roller_blocks(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device without roller blocks."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[ROLLER_BLOCK_ID], "type", None)
|
||||
|
@ -97,7 +101,7 @@ async def test_rpc_device_services(
|
|||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test RPC device cover services."""
|
||||
entity_id = "cover.test_cover_0"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""The tests for Shelly device triggers."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from aioshelly.const import MODEL_BUTTON1
|
||||
import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
@ -16,9 +18,10 @@ from homeassistant.components.shelly.const import (
|
|||
EVENT_SHELLY_CLICK,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICE_ID, CONF_DOMAIN, CONF_PLATFORM, CONF_TYPE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
DeviceRegistry,
|
||||
async_entries_for_config_entry,
|
||||
async_get as async_get_dev_reg,
|
||||
)
|
||||
|
@ -39,7 +42,11 @@ from tests.common import MockConfigEntry, async_get_device_automations
|
|||
],
|
||||
)
|
||||
async def test_get_triggers_block_device(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch, button_type, is_valid
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
button_type: str,
|
||||
is_valid: bool,
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a shelly block device."""
|
||||
monkeypatch.setitem(
|
||||
|
@ -75,7 +82,9 @@ async def test_get_triggers_block_device(
|
|||
assert triggers == unordered(expected_triggers)
|
||||
|
||||
|
||||
async def test_get_triggers_rpc_device(hass: HomeAssistant, mock_rpc_device) -> None:
|
||||
async def test_get_triggers_rpc_device(
|
||||
hass: HomeAssistant, mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a shelly RPC device."""
|
||||
entry = await init_integration(hass, 2)
|
||||
dev_reg = async_get_dev_reg(hass)
|
||||
|
@ -107,7 +116,9 @@ async def test_get_triggers_rpc_device(hass: HomeAssistant, mock_rpc_device) ->
|
|||
assert triggers == unordered(expected_triggers)
|
||||
|
||||
|
||||
async def test_get_triggers_button(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_get_triggers_button(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test we get the expected triggers from a shelly button."""
|
||||
entry = await init_integration(hass, 1, model=MODEL_BUTTON1)
|
||||
dev_reg = async_get_dev_reg(hass)
|
||||
|
@ -133,7 +144,7 @@ async def test_get_triggers_button(hass: HomeAssistant, mock_block_device) -> No
|
|||
|
||||
|
||||
async def test_get_triggers_non_initialized_devices(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test we get the empty triggers for non-initialized devices."""
|
||||
monkeypatch.setattr(mock_block_device, "initialized", False)
|
||||
|
@ -151,7 +162,7 @@ async def test_get_triggers_non_initialized_devices(
|
|||
|
||||
|
||||
async def test_get_triggers_for_invalid_device_id(
|
||||
hass: HomeAssistant, device_reg, mock_block_device
|
||||
hass: HomeAssistant, device_reg: DeviceRegistry, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test error raised for invalid shelly device_id."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -169,7 +180,7 @@ async def test_get_triggers_for_invalid_device_id(
|
|||
|
||||
|
||||
async def test_if_fires_on_click_event_block_device(
|
||||
hass: HomeAssistant, calls, mock_block_device
|
||||
hass: HomeAssistant, calls: list[ServiceCall], mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test for click_event trigger firing for block device."""
|
||||
entry = await init_integration(hass, 1)
|
||||
|
@ -211,7 +222,7 @@ async def test_if_fires_on_click_event_block_device(
|
|||
|
||||
|
||||
async def test_if_fires_on_click_event_rpc_device(
|
||||
hass: HomeAssistant, calls, mock_rpc_device
|
||||
hass: HomeAssistant, calls: list[ServiceCall], mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test for click_event trigger firing for rpc device."""
|
||||
entry = await init_integration(hass, 2)
|
||||
|
@ -253,7 +264,10 @@ async def test_if_fires_on_click_event_rpc_device(
|
|||
|
||||
|
||||
async def test_validate_trigger_block_device_not_ready(
|
||||
hass: HomeAssistant, calls, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
calls: list[ServiceCall],
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test validate trigger config when block device is not ready."""
|
||||
monkeypatch.setattr(mock_block_device, "initialized", False)
|
||||
|
@ -295,7 +309,10 @@ async def test_validate_trigger_block_device_not_ready(
|
|||
|
||||
|
||||
async def test_validate_trigger_rpc_device_not_ready(
|
||||
hass: HomeAssistant, calls, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
calls: list[ServiceCall],
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test validate trigger config when RPC device is not ready."""
|
||||
monkeypatch.setattr(mock_rpc_device, "initialized", False)
|
||||
|
@ -337,7 +354,7 @@ async def test_validate_trigger_rpc_device_not_ready(
|
|||
|
||||
|
||||
async def test_validate_trigger_invalid_triggers(
|
||||
hass: HomeAssistant, mock_block_device, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant, mock_block_device: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test for click_event with invalid triggers."""
|
||||
entry = await init_integration(hass, 1)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"""Tests for Shelly diagnostics platform."""
|
||||
from unittest.mock import ANY
|
||||
from unittest.mock import ANY, Mock
|
||||
|
||||
from aioshelly.ble.const import BLE_SCAN_RESULT_EVENT
|
||||
from aioshelly.const import MODEL_25
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.components.shelly.const import (
|
||||
|
@ -23,7 +24,7 @@ RELAY_BLOCK_ID = 0
|
|||
|
||||
|
||||
async def test_block_config_entry_diagnostics(
|
||||
hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_block_device
|
||||
hass: HomeAssistant, hass_client: ClientSessionGenerator, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test config entry diagnostics for block device."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -52,8 +53,8 @@ async def test_block_config_entry_diagnostics(
|
|||
async def test_rpc_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics for rpc device."""
|
||||
await init_integration(
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""Tests for Shelly button platform."""
|
||||
from __future__ import annotations
|
||||
from unittest.mock import Mock
|
||||
|
||||
from aioshelly.const import MODEL_I3
|
||||
import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components.event import (
|
||||
|
@ -12,6 +13,7 @@ from homeassistant.components.event import (
|
|||
)
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, inject_rpc_device_event, register_entity
|
||||
|
||||
|
@ -19,7 +21,10 @@ DEVICE_BLOCK_ID = 4
|
|||
|
||||
|
||||
async def test_rpc_button(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC device event."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -59,7 +64,10 @@ async def test_rpc_button(
|
|||
|
||||
|
||||
async def test_rpc_event_removal(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC event entity is removed due to removal_condition."""
|
||||
entity_id = register_entity(hass, EVENT_DOMAIN, "test_name_input_0", "input:0")
|
||||
|
@ -73,7 +81,10 @@ async def test_rpc_event_removal(
|
|||
|
||||
|
||||
async def test_block_event(
|
||||
hass: HomeAssistant, monkeypatch, mock_block_device, entity_registry
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
) -> None:
|
||||
"""Test block device event."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -103,7 +114,9 @@ async def test_block_event(
|
|||
assert state.attributes.get(ATTR_EVENT_TYPE) == "long"
|
||||
|
||||
|
||||
async def test_block_event_shix3_1(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_block_event_shix3_1(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test block device event for SHIX3-1."""
|
||||
await init_integration(hass, 1, model=MODEL_I3)
|
||||
entity_id = "event.test_name_channel_1"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Test cases for the Shelly component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, Mock, patch
|
||||
|
||||
from aioshelly.exceptions import (
|
||||
DeviceConnectionError,
|
||||
|
@ -23,7 +21,11 @@ from homeassistant.components.shelly.const import (
|
|||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, format_mac
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
DeviceRegistry,
|
||||
format_mac,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import MOCK_MAC, init_integration, mutate_rpc_device_status
|
||||
|
@ -32,7 +34,7 @@ from tests.common import MockConfigEntry
|
|||
|
||||
|
||||
async def test_custom_coap_port(
|
||||
hass: HomeAssistant, mock_block_device, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant, mock_block_device: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test custom coap port."""
|
||||
assert await async_setup_component(
|
||||
|
@ -49,10 +51,10 @@ async def test_custom_coap_port(
|
|||
@pytest.mark.parametrize("gen", [1, 2, 3])
|
||||
async def test_shared_device_mac(
|
||||
hass: HomeAssistant,
|
||||
gen,
|
||||
mock_block_device,
|
||||
mock_rpc_device,
|
||||
device_reg,
|
||||
gen: int,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test first time shared device with another domain."""
|
||||
|
@ -83,11 +85,11 @@ async def test_setup_entry_not_shelly(
|
|||
@pytest.mark.parametrize("side_effect", [DeviceConnectionError, FirmwareUnsupported])
|
||||
async def test_device_connection_error(
|
||||
hass: HomeAssistant,
|
||||
gen,
|
||||
side_effect,
|
||||
mock_block_device,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
gen: int,
|
||||
side_effect: Exception,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test device connection error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -103,7 +105,11 @@ async def test_device_connection_error(
|
|||
|
||||
@pytest.mark.parametrize("gen", [1, 2, 3])
|
||||
async def test_mac_mismatch_error(
|
||||
hass: HomeAssistant, gen, mock_block_device, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test device MAC address mismatch error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -119,7 +125,11 @@ async def test_mac_mismatch_error(
|
|||
|
||||
@pytest.mark.parametrize("gen", [1, 2, 3])
|
||||
async def test_device_auth_error(
|
||||
hass: HomeAssistant, gen, mock_block_device, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test device authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -147,10 +157,10 @@ async def test_device_auth_error(
|
|||
@pytest.mark.parametrize(("entry_sleep", "device_sleep"), [(None, 0), (1000, 1000)])
|
||||
async def test_sleeping_block_device_online(
|
||||
hass: HomeAssistant,
|
||||
entry_sleep,
|
||||
device_sleep,
|
||||
mock_block_device,
|
||||
device_reg,
|
||||
entry_sleep: int | None,
|
||||
device_sleep: int,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test sleeping block device online."""
|
||||
|
@ -172,9 +182,9 @@ async def test_sleeping_block_device_online(
|
|||
@pytest.mark.parametrize(("entry_sleep", "device_sleep"), [(None, 0), (1000, 1000)])
|
||||
async def test_sleeping_rpc_device_online(
|
||||
hass: HomeAssistant,
|
||||
entry_sleep,
|
||||
device_sleep,
|
||||
mock_rpc_device,
|
||||
entry_sleep: int | None,
|
||||
device_sleep: int,
|
||||
mock_rpc_device: Mock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test sleeping RPC device online."""
|
||||
|
@ -188,8 +198,8 @@ async def test_sleeping_rpc_device_online(
|
|||
|
||||
async def test_sleeping_rpc_device_online_new_firmware(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test sleeping device Gen2 with firmware 1.0.0 or later."""
|
||||
|
@ -210,7 +220,11 @@ async def test_sleeping_rpc_device_online_new_firmware(
|
|||
],
|
||||
)
|
||||
async def test_entry_unload(
|
||||
hass: HomeAssistant, gen, entity_id, mock_block_device, mock_rpc_device
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
entity_id: str,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test entry unload."""
|
||||
entry = await init_integration(hass, gen)
|
||||
|
@ -233,7 +247,11 @@ async def test_entry_unload(
|
|||
],
|
||||
)
|
||||
async def test_entry_unload_device_not_ready(
|
||||
hass: HomeAssistant, gen, entity_id, mock_block_device, mock_rpc_device
|
||||
hass: HomeAssistant,
|
||||
gen: int,
|
||||
entity_id: str,
|
||||
mock_block_device: Mock,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test entry unload when device is not ready."""
|
||||
entry = await init_integration(hass, gen, sleep_period=1000)
|
||||
|
@ -248,7 +266,7 @@ async def test_entry_unload_device_not_ready(
|
|||
|
||||
|
||||
async def test_entry_unload_not_connected(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test entry unload when not connected."""
|
||||
with patch(
|
||||
|
@ -273,7 +291,7 @@ async def test_entry_unload_not_connected(
|
|||
|
||||
|
||||
async def test_entry_unload_not_connected_but_we_think_we_are(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test entry unload when not connected but we think we are still connected."""
|
||||
with patch(
|
||||
|
@ -299,7 +317,7 @@ async def test_entry_unload_not_connected_but_we_think_we_are(
|
|||
|
||||
|
||||
async def test_no_attempt_to_stop_scanner_with_sleepy_devices(
|
||||
hass: HomeAssistant, mock_rpc_device
|
||||
hass: HomeAssistant, mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test we do not try to stop the scanner if its disabled with a sleepy device."""
|
||||
with patch(
|
||||
|
@ -314,7 +332,7 @@ async def test_no_attempt_to_stop_scanner_with_sleepy_devices(
|
|||
assert not mock_stop_scanner.call_count
|
||||
|
||||
|
||||
async def test_entry_missing_gen(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_entry_missing_gen(hass: HomeAssistant, mock_block_device: Mock) -> None:
|
||||
"""Test successful Gen1 device init when gen is missing in entry data."""
|
||||
entry = await init_integration(hass, None)
|
||||
|
||||
|
@ -324,7 +342,7 @@ async def test_entry_missing_gen(hass: HomeAssistant, mock_block_device) -> None
|
|||
|
||||
@pytest.mark.parametrize(("model"), MODELS_WITH_WRONG_SLEEP_PERIOD)
|
||||
async def test_sleeping_block_device_wrong_sleep_period(
|
||||
hass: HomeAssistant, mock_block_device, model
|
||||
hass: HomeAssistant, mock_block_device: Mock, model: str
|
||||
) -> None:
|
||||
"""Test sleeping block device with wrong sleep period."""
|
||||
entry = await init_integration(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for Shelly light platform."""
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from aioshelly.const import (
|
||||
MODEL_BULB,
|
||||
|
@ -35,6 +35,7 @@ from homeassistant.const import (
|
|||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, mutate_rpc_device_status
|
||||
from .conftest import mock_white_light_set_state
|
||||
|
@ -44,7 +45,7 @@ LIGHT_BLOCK_ID = 2
|
|||
|
||||
|
||||
async def test_block_device_rgbw_bulb(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry
|
||||
hass: HomeAssistant, mock_block_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test block device RGBW bulb."""
|
||||
entity_id = "light.test_name_channel_1"
|
||||
|
@ -126,9 +127,9 @@ async def test_block_device_rgbw_bulb(
|
|||
|
||||
async def test_block_device_rgb_bulb(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
entity_registry,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry: EntityRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test block device RGB bulb."""
|
||||
|
@ -235,9 +236,9 @@ async def test_block_device_rgb_bulb(
|
|||
|
||||
async def test_block_device_white_bulb(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device white bulb."""
|
||||
entity_id = "light.test_name_channel_1"
|
||||
|
@ -312,7 +313,11 @@ async def test_block_device_white_bulb(
|
|||
],
|
||||
)
|
||||
async def test_block_device_support_transition(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, model, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
model: str,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device supports transition."""
|
||||
entity_id = "light.test_name_channel_1"
|
||||
|
@ -363,7 +368,10 @@ async def test_block_device_support_transition(
|
|||
|
||||
|
||||
async def test_block_device_relay_app_type_light(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device relay in app type set to light mode."""
|
||||
entity_id = "light.test_name_channel_1"
|
||||
|
@ -425,7 +433,7 @@ async def test_block_device_relay_app_type_light(
|
|||
|
||||
|
||||
async def test_block_device_no_light_blocks(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device without light blocks."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[LIGHT_BLOCK_ID], "type", "roller")
|
||||
|
@ -434,7 +442,10 @@ async def test_block_device_no_light_blocks(
|
|||
|
||||
|
||||
async def test_rpc_device_switch_type_lights_mode(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC device with switch in consumption type lights mode."""
|
||||
entity_id = "light.test_switch_0"
|
||||
|
@ -467,7 +478,10 @@ async def test_rpc_device_switch_type_lights_mode(
|
|||
|
||||
|
||||
async def test_rpc_light(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC light."""
|
||||
entity_id = f"{LIGHT_DOMAIN}.test_light_0"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""The tests for Shelly logbook."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from homeassistant.components.shelly.const import (
|
||||
ATTR_CHANNEL,
|
||||
ATTR_CLICK_TYPE,
|
||||
|
@ -20,7 +22,7 @@ from tests.components.logbook.common import MockRow, mock_humanify
|
|||
|
||||
|
||||
async def test_humanify_shelly_click_event_block_device(
|
||||
hass: HomeAssistant, mock_block_device
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test humanifying Shelly click event for block device."""
|
||||
entry = await init_integration(hass, 1)
|
||||
|
@ -70,7 +72,7 @@ async def test_humanify_shelly_click_event_block_device(
|
|||
|
||||
|
||||
async def test_humanify_shelly_click_event_rpc_device(
|
||||
hass: HomeAssistant, mock_rpc_device
|
||||
hass: HomeAssistant, mock_rpc_device: Mock
|
||||
) -> None:
|
||||
"""Test humanifying Shelly click event for rpc device."""
|
||||
entry = await init_integration(hass, 2)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for Shelly number platform."""
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
|
||||
import pytest
|
||||
|
@ -14,6 +14,8 @@ from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
|||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import init_integration, register_device, register_entity
|
||||
|
||||
|
@ -23,7 +25,10 @@ DEVICE_BLOCK_ID = 4
|
|||
|
||||
|
||||
async def test_block_number_update(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device number update."""
|
||||
entity_id = "number.test_name_valve_position"
|
||||
|
@ -48,7 +53,10 @@ async def test_block_number_update(
|
|||
|
||||
|
||||
async def test_block_restored_number(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored number."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -91,7 +99,10 @@ async def test_block_restored_number(
|
|||
|
||||
|
||||
async def test_block_restored_number_no_last_state(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored number missing last state."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -124,7 +135,9 @@ async def test_block_restored_number_no_last_state(
|
|||
assert hass.states.get(entity_id).state == "50"
|
||||
|
||||
|
||||
async def test_block_number_set_value(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_block_number_set_value(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test block device number set value."""
|
||||
await init_integration(hass, 1, sleep_period=1000)
|
||||
|
||||
|
@ -145,7 +158,7 @@ async def test_block_number_set_value(hass: HomeAssistant, mock_block_device) ->
|
|||
|
||||
|
||||
async def test_block_set_value_connection_error(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device set value connection error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -169,7 +182,7 @@ async def test_block_set_value_connection_error(
|
|||
|
||||
|
||||
async def test_block_set_value_auth_error(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device set value authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.const import (
|
|||
UnitOfEnergy,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry, async_get
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -46,7 +47,10 @@ DEVICE_BLOCK_ID = 4
|
|||
|
||||
|
||||
async def test_block_sensor(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_channel_1_power"
|
||||
|
@ -65,7 +69,7 @@ async def test_block_sensor(
|
|||
|
||||
|
||||
async def test_energy_sensor(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry
|
||||
hass: HomeAssistant, mock_block_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test energy sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_channel_1_energy"
|
||||
|
@ -83,7 +87,7 @@ async def test_energy_sensor(
|
|||
|
||||
|
||||
async def test_power_factory_unit_migration(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry
|
||||
hass: HomeAssistant, mock_block_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test migration unit of the power factory sensor."""
|
||||
entity_registry.async_get_or_create(
|
||||
|
@ -108,7 +112,7 @@ async def test_power_factory_unit_migration(
|
|||
|
||||
|
||||
async def test_power_factory_without_unit_migration(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry
|
||||
hass: HomeAssistant, mock_block_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test unit and value of the power factory sensor without unit migration."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_power_factor"
|
||||
|
@ -124,7 +128,10 @@ async def test_power_factory_without_unit_migration(
|
|||
|
||||
|
||||
async def test_block_rest_sensor(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block REST sensor."""
|
||||
entity_id = register_entity(hass, SENSOR_DOMAIN, "test_name_rssi", "rssi")
|
||||
|
@ -139,7 +146,10 @@ async def test_block_rest_sensor(
|
|||
|
||||
|
||||
async def test_block_sleeping_sensor(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block sleeping sensor."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -168,7 +178,10 @@ async def test_block_sleeping_sensor(
|
|||
|
||||
|
||||
async def test_block_restored_sleeping_sensor(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored sleeping sensor."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -198,7 +211,10 @@ async def test_block_restored_sleeping_sensor(
|
|||
|
||||
|
||||
async def test_block_restored_sleeping_sensor_no_last_state(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block restored sleeping sensor missing last state."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -221,7 +237,10 @@ async def test_block_restored_sleeping_sensor_no_last_state(
|
|||
|
||||
|
||||
async def test_block_sensor_error(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block sensor unavailable on sensor error."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_battery"
|
||||
|
@ -240,7 +259,10 @@ async def test_block_sensor_error(
|
|||
|
||||
|
||||
async def test_block_sensor_removal(
|
||||
hass: HomeAssistant, mock_block_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block sensor is removed due to removal_condition."""
|
||||
entity_id = register_entity(
|
||||
|
@ -256,7 +278,10 @@ async def test_block_sensor_removal(
|
|||
|
||||
|
||||
async def test_block_not_matched_restored_sleeping_sensor(
|
||||
hass: HomeAssistant, mock_block_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block not matched to restored sleeping sensor."""
|
||||
entry = await init_integration(hass, 1, sleep_period=1000, skip_setup=True)
|
||||
|
@ -285,7 +310,7 @@ async def test_block_not_matched_restored_sleeping_sensor(
|
|||
|
||||
|
||||
async def test_block_sensor_without_value(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block sensor without value is not created."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_battery"
|
||||
|
@ -296,7 +321,7 @@ async def test_block_sensor_without_value(
|
|||
|
||||
|
||||
async def test_block_sensor_unknown_value(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block sensor unknown value."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_battery"
|
||||
|
@ -308,7 +333,9 @@ async def test_block_sensor_unknown_value(
|
|||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_rpc_sensor(hass: HomeAssistant, mock_rpc_device, monkeypatch) -> None:
|
||||
async def test_rpc_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test RPC sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_cover_0_power"
|
||||
await init_integration(hass, 2)
|
||||
|
@ -327,7 +354,7 @@ async def test_rpc_sensor(hass: HomeAssistant, mock_rpc_device, monkeypatch) ->
|
|||
|
||||
|
||||
async def test_rpc_illuminance_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test RPC illuminacne sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_illuminance"
|
||||
|
@ -341,7 +368,10 @@ async def test_rpc_illuminance_sensor(
|
|||
|
||||
|
||||
async def test_rpc_sensor_error(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC sensor unavailable on sensor error."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_voltmeter"
|
||||
|
@ -362,9 +392,9 @@ async def test_rpc_sensor_error(
|
|||
async def test_rpc_polling_sensor(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC polling sensor."""
|
||||
entity_id = register_entity(hass, SENSOR_DOMAIN, "test_name_rssi", "wifi-rssi")
|
||||
|
@ -383,7 +413,10 @@ async def test_rpc_polling_sensor(
|
|||
|
||||
|
||||
async def test_rpc_sleeping_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC online sleeping sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_temperature"
|
||||
|
@ -413,7 +446,10 @@ async def test_rpc_sleeping_sensor(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored sensor."""
|
||||
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
|
||||
|
@ -444,7 +480,10 @@ async def test_rpc_restored_sleeping_sensor(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_sensor_no_last_state(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored sensor missing last state."""
|
||||
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
|
||||
|
@ -473,7 +512,7 @@ async def test_rpc_restored_sleeping_sensor_no_last_state(
|
|||
|
||||
|
||||
async def test_rpc_em1_sensors(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry_enabled_by_default: None
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, entity_registry_enabled_by_default: None
|
||||
) -> None:
|
||||
"""Test RPC sensors for EM1 component."""
|
||||
registry = async_get(hass)
|
||||
|
@ -514,8 +553,8 @@ async def test_rpc_em1_sensors(
|
|||
|
||||
async def test_rpc_sleeping_update_entity_service(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device,
|
||||
entity_registry,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test RPC sleeping device when the update_entity service is used."""
|
||||
|
@ -558,8 +597,8 @@ async def test_rpc_sleeping_update_entity_service(
|
|||
|
||||
async def test_block_sleeping_update_entity_service(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
entity_registry,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test block sleeping device when the update_entity service is used."""
|
||||
|
@ -600,7 +639,7 @@ async def test_block_sleeping_update_entity_service(
|
|||
|
||||
|
||||
async def test_rpc_analog_input_xpercent_sensor(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test RPC analog input xpercent sensor."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_input_0_analog_value"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Tests for Shelly switch platform."""
|
||||
from copy import deepcopy
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from aioshelly.const import MODEL_GAS
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
||||
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
import homeassistant.helpers.issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -32,7 +32,9 @@ RELAY_BLOCK_ID = 0
|
|||
GAS_VALVE_BLOCK_ID = 6
|
||||
|
||||
|
||||
async def test_block_device_services(hass: HomeAssistant, mock_block_device) -> None:
|
||||
async def test_block_device_services(
|
||||
hass: HomeAssistant, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test block device turn on/off services."""
|
||||
await init_integration(hass, 1)
|
||||
|
||||
|
@ -54,7 +56,7 @@ async def test_block_device_services(hass: HomeAssistant, mock_block_device) ->
|
|||
|
||||
|
||||
async def test_block_device_unique_ids(
|
||||
hass: HomeAssistant, entity_registry, mock_block_device
|
||||
hass: HomeAssistant, entity_registry: EntityRegistry, mock_block_device: Mock
|
||||
) -> None:
|
||||
"""Test block device unique_ids."""
|
||||
await init_integration(hass, 1)
|
||||
|
@ -85,7 +87,7 @@ async def test_block_set_state_connection_error(
|
|||
|
||||
|
||||
async def test_block_set_state_auth_error(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device set state authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -120,7 +122,7 @@ async def test_block_set_state_auth_error(
|
|||
|
||||
|
||||
async def test_block_device_update(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device update."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[RELAY_BLOCK_ID], "output", False)
|
||||
|
@ -133,7 +135,7 @@ async def test_block_device_update(
|
|||
|
||||
|
||||
async def test_block_device_no_relay_blocks(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device without relay blocks."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[RELAY_BLOCK_ID], "type", "roller")
|
||||
|
@ -142,7 +144,7 @@ async def test_block_device_no_relay_blocks(
|
|||
|
||||
|
||||
async def test_block_device_mode_roller(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device in roller mode."""
|
||||
monkeypatch.setitem(mock_block_device.settings, "mode", "roller")
|
||||
|
@ -151,7 +153,7 @@ async def test_block_device_mode_roller(
|
|||
|
||||
|
||||
async def test_block_device_app_type_light(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device in app type set to light mode."""
|
||||
monkeypatch.setitem(
|
||||
|
@ -162,7 +164,7 @@ async def test_block_device_app_type_light(
|
|||
|
||||
|
||||
async def test_rpc_device_services(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test RPC device turn on/off services."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -187,7 +189,7 @@ async def test_rpc_device_services(
|
|||
|
||||
|
||||
async def test_rpc_device_unique_ids(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, entity_registry: EntityRegistry
|
||||
) -> None:
|
||||
"""Test RPC device unique_ids."""
|
||||
await init_integration(hass, 2)
|
||||
|
@ -198,7 +200,7 @@ async def test_rpc_device_unique_ids(
|
|||
|
||||
|
||||
async def test_rpc_device_switch_type_lights_mode(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test RPC device with switch in consumption type lights mode."""
|
||||
monkeypatch.setitem(
|
||||
|
@ -210,7 +212,10 @@ async def test_rpc_device_switch_type_lights_mode(
|
|||
|
||||
@pytest.mark.parametrize("exc", [DeviceConnectionError, RpcCallError(-1, "error")])
|
||||
async def test_rpc_set_state_errors(
|
||||
hass: HomeAssistant, exc, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
exc: Exception,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC device set state connection/call errors."""
|
||||
monkeypatch.setattr(mock_rpc_device, "call_rpc", AsyncMock(side_effect=exc))
|
||||
|
@ -226,7 +231,7 @@ async def test_rpc_set_state_errors(
|
|||
|
||||
|
||||
async def test_rpc_auth_error(
|
||||
hass: HomeAssistant, mock_rpc_device, monkeypatch
|
||||
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test RPC device set state authentication error."""
|
||||
monkeypatch.setattr(
|
||||
|
@ -261,7 +266,10 @@ async def test_rpc_auth_error(
|
|||
|
||||
|
||||
async def test_block_device_gas_valve(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test block device Shelly Gas with Valve addon."""
|
||||
entity_id = register_entity(
|
||||
|
@ -270,10 +278,9 @@ async def test_block_device_gas_valve(
|
|||
"test_name_valve",
|
||||
"valve_0-valve",
|
||||
)
|
||||
registry = er.async_get(hass)
|
||||
await init_integration(hass, 1, MODEL_GAS)
|
||||
|
||||
entry = registry.async_get(entity_id)
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
assert entry
|
||||
assert entry.unique_id == "123456789ABC-valve_0-valve"
|
||||
|
||||
|
@ -312,7 +319,7 @@ async def test_block_device_gas_valve(
|
|||
|
||||
async def test_wall_display_thermostat_mode(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device,
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test Wall Display in thermostat mode."""
|
||||
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
|
||||
|
@ -324,9 +331,8 @@ async def test_wall_display_thermostat_mode(
|
|||
|
||||
async def test_wall_display_relay_mode(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test Wall Display in thermostat mode."""
|
||||
entity_id = register_entity(
|
||||
|
@ -348,9 +354,9 @@ async def test_wall_display_relay_mode(
|
|||
|
||||
async def test_create_issue_valve_switch(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
mock_block_device: Mock,
|
||||
entity_registry_enabled_by_default: None,
|
||||
monkeypatch,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test we create an issue when an automation or script is using a deprecated entity."""
|
||||
monkeypatch.setitem(mock_block_device.status, "cloud", {"connected": False})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Tests for Shelly update platform."""
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
|
||||
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError, RpcCallError
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
|
@ -29,6 +29,8 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
|
||||
from . import (
|
||||
init_integration,
|
||||
|
@ -44,9 +46,9 @@ from tests.common import mock_restore_cache
|
|||
async def test_block_update(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
"""Test block device update entity."""
|
||||
|
@ -96,9 +98,9 @@ async def test_block_update(
|
|||
async def test_block_beta_update(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_block_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
"""Test block device beta update entity."""
|
||||
|
@ -155,8 +157,8 @@ async def test_block_beta_update(
|
|||
|
||||
async def test_block_update_connection_error(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
|
@ -182,8 +184,8 @@ async def test_block_update_connection_error(
|
|||
|
||||
async def test_block_update_auth_error(
|
||||
hass: HomeAssistant,
|
||||
mock_block_device,
|
||||
monkeypatch,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
"""Test block device update authentication error."""
|
||||
|
@ -221,7 +223,10 @@ async def test_block_update_auth_error(
|
|||
|
||||
|
||||
async def test_rpc_update(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC device update entity."""
|
||||
entity_id = "update.test_name_firmware_update"
|
||||
|
@ -320,7 +325,10 @@ async def test_rpc_update(
|
|||
|
||||
|
||||
async def test_rpc_sleeping_update(
|
||||
hass: HomeAssistant, mock_rpc_device, entity_registry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC sleeping device update entity."""
|
||||
monkeypatch.setitem(mock_rpc_device.shelly, "ver", "1")
|
||||
|
@ -365,7 +373,10 @@ async def test_rpc_sleeping_update(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_update(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored update entity."""
|
||||
entry = await init_integration(hass, 2, sleep_period=1000, skip_setup=True)
|
||||
|
@ -408,7 +419,10 @@ async def test_rpc_restored_sleeping_update(
|
|||
|
||||
|
||||
async def test_rpc_restored_sleeping_update_no_last_state(
|
||||
hass: HomeAssistant, mock_rpc_device, device_reg, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device: Mock,
|
||||
device_reg: DeviceRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Test RPC restored update entity missing last state."""
|
||||
monkeypatch.setitem(mock_rpc_device.shelly, "ver", "1")
|
||||
|
@ -452,9 +466,9 @@ async def test_rpc_restored_sleeping_update_no_last_state(
|
|||
async def test_rpc_beta_update(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
mock_rpc_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
"""Test RPC device beta update entity."""
|
||||
|
@ -577,10 +591,10 @@ async def test_rpc_beta_update(
|
|||
)
|
||||
async def test_rpc_update_errors(
|
||||
hass: HomeAssistant,
|
||||
exc,
|
||||
error,
|
||||
mock_rpc_device,
|
||||
monkeypatch,
|
||||
exc: Exception,
|
||||
error: str,
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
|
@ -611,9 +625,9 @@ async def test_rpc_update_errors(
|
|||
|
||||
async def test_rpc_update_auth_error(
|
||||
hass: HomeAssistant,
|
||||
mock_rpc_device,
|
||||
entity_registry,
|
||||
monkeypatch,
|
||||
mock_rpc_device: Mock,
|
||||
entity_registry: EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity_registry_enabled_by_default: None,
|
||||
) -> None:
|
||||
"""Test RPC device update authentication error."""
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
"""Tests for Shelly utils."""
|
||||
from typing import Any
|
||||
from unittest.mock import Mock
|
||||
|
||||
from aioshelly.const import (
|
||||
MODEL_1,
|
||||
MODEL_1L,
|
||||
|
@ -30,7 +33,9 @@ from homeassistant.util import dt as dt_util
|
|||
DEVICE_BLOCK_ID = 4
|
||||
|
||||
|
||||
async def test_block_get_number_of_channels(mock_block_device, monkeypatch) -> None:
|
||||
async def test_block_get_number_of_channels(
|
||||
mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block get number of channels."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "type", "emeter")
|
||||
monkeypatch.setitem(mock_block_device.shelly, "num_emeters", 3)
|
||||
|
@ -63,7 +68,9 @@ async def test_block_get_number_of_channels(mock_block_device, monkeypatch) -> N
|
|||
)
|
||||
|
||||
|
||||
async def test_block_get_block_channel_name(mock_block_device, monkeypatch) -> None:
|
||||
async def test_block_get_block_channel_name(
|
||||
mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block get block channel name."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "type", "relay")
|
||||
|
||||
|
@ -98,7 +105,9 @@ async def test_block_get_block_channel_name(mock_block_device, monkeypatch) -> N
|
|||
)
|
||||
|
||||
|
||||
async def test_is_block_momentary_input(mock_block_device, monkeypatch) -> None:
|
||||
async def test_is_block_momentary_input(
|
||||
mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test is block momentary input."""
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "type", "relay")
|
||||
|
||||
|
@ -158,7 +167,9 @@ async def test_is_block_momentary_input(mock_block_device, monkeypatch) -> None:
|
|||
({"sleep_mode": {"period": 5, "unit": "h"}}, 5 * 3600),
|
||||
],
|
||||
)
|
||||
async def test_get_block_device_sleep_period(settings, sleep_period) -> None:
|
||||
async def test_get_block_device_sleep_period(
|
||||
settings: dict[str, Any], sleep_period: int
|
||||
) -> None:
|
||||
"""Test get block device sleep period."""
|
||||
assert get_block_device_sleep_period(settings) == sleep_period
|
||||
|
||||
|
@ -175,7 +186,9 @@ async def test_get_device_uptime() -> None:
|
|||
) == dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:42:10+00:00"))
|
||||
|
||||
|
||||
async def test_get_block_input_triggers(mock_block_device, monkeypatch) -> None:
|
||||
async def test_get_block_input_triggers(
|
||||
mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test get block input triggers."""
|
||||
monkeypatch.setattr(
|
||||
mock_block_device.blocks[DEVICE_BLOCK_ID],
|
||||
|
@ -218,13 +231,15 @@ async def test_get_block_input_triggers(mock_block_device, monkeypatch) -> None:
|
|||
}
|
||||
|
||||
|
||||
async def test_get_rpc_channel_name(mock_rpc_device) -> None:
|
||||
async def test_get_rpc_channel_name(mock_rpc_device: Mock) -> None:
|
||||
"""Test get RPC channel name."""
|
||||
assert get_rpc_channel_name(mock_rpc_device, "input:0") == "Test name input 0"
|
||||
assert get_rpc_channel_name(mock_rpc_device, "input:3") == "Test name input_3"
|
||||
|
||||
|
||||
async def test_get_rpc_input_triggers(mock_rpc_device, monkeypatch) -> None:
|
||||
async def test_get_rpc_input_triggers(
|
||||
mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test get RPC input triggers."""
|
||||
monkeypatch.setattr(mock_rpc_device, "config", {"input:0": {"type": "button"}})
|
||||
assert set(get_rpc_input_triggers(mock_rpc_device)) == {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
"""Tests for Shelly valve platform."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from aioshelly.const import MODEL_GAS
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.valve import DOMAIN as VALVE_DOMAIN
|
||||
from homeassistant.const import (
|
||||
|
@ -20,7 +23,7 @@ GAS_VALVE_BLOCK_ID = 6
|
|||
|
||||
|
||||
async def test_block_device_gas_valve(
|
||||
hass: HomeAssistant, mock_block_device, monkeypatch
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test block device Shelly Gas with Valve addon."""
|
||||
registry = er.async_get(hass)
|
||||
|
|
Loading…
Reference in a new issue