mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Improve Netatmo tests (#107902)
* Improve Netatmo tests * Improve Netatmo tests
This commit is contained in:
parent
68698cacac
commit
7bcfcfef5f
@ -1,17 +1,17 @@
|
||||
"""Common methods used across tests for Netatmo."""
|
||||
from contextlib import contextmanager
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant.components.webhook import async_handle_webhook
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.aiohttp import MockRequest
|
||||
|
||||
from tests.common import load_fixture
|
||||
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
||||
|
||||
CLIENT_ID = "1234"
|
||||
CLIENT_SECRET = "5678"
|
||||
|
||||
COMMON_RESPONSE = {
|
||||
"user_id": "91763b24c43d3e344f424e8d",
|
||||
"home_id": "91763b24c43d3e344f424e8b",
|
||||
@ -19,16 +19,12 @@ COMMON_RESPONSE = {
|
||||
"user": {"id": "91763b24c43d3e344f424e8b", "email": "john@doe.com"},
|
||||
}
|
||||
|
||||
TEST_TIME = 1559347200.0
|
||||
|
||||
FAKE_WEBHOOK_ACTIVATION = {
|
||||
"push_type": "webhook_activation",
|
||||
}
|
||||
|
||||
DEFAULT_PLATFORMS = ["camera", "climate", "light", "sensor"]
|
||||
|
||||
|
||||
async def fake_post_request(*args, **kwargs):
|
||||
async def fake_post_request(*args: Any, **kwargs: Any):
|
||||
"""Return fake data."""
|
||||
if "endpoint" not in kwargs:
|
||||
return "{}"
|
||||
@ -62,7 +58,7 @@ async def fake_post_request(*args, **kwargs):
|
||||
)
|
||||
|
||||
|
||||
async def fake_get_image(*args, **kwargs):
|
||||
async def fake_get_image(*args: Any, **kwargs: Any) -> bytes | str:
|
||||
"""Return fake data."""
|
||||
if "endpoint" not in kwargs:
|
||||
return "{}"
|
||||
@ -73,12 +69,7 @@ async def fake_get_image(*args, **kwargs):
|
||||
return b"test stream image bytes"
|
||||
|
||||
|
||||
async def fake_post_request_no_data(*args, **kwargs):
|
||||
"""Fake error during requesting backend data."""
|
||||
return "{}"
|
||||
|
||||
|
||||
async def simulate_webhook(hass, webhook_id, response):
|
||||
async def simulate_webhook(hass: HomeAssistant, webhook_id: str, response) -> None:
|
||||
"""Simulate a webhook event."""
|
||||
request = MockRequest(
|
||||
method="POST",
|
||||
@ -90,7 +81,7 @@ async def simulate_webhook(hass, webhook_id, response):
|
||||
|
||||
|
||||
@contextmanager
|
||||
def selected_platforms(platforms):
|
||||
def selected_platforms(platforms: list[Platform]) -> AsyncMock:
|
||||
"""Restrict loaded platforms to list given."""
|
||||
with patch(
|
||||
"homeassistant.components.netatmo.data_handler.PLATFORMS", platforms
|
||||
|
@ -5,13 +5,15 @@ from unittest.mock import AsyncMock, patch
|
||||
from pyatmo.const import ALL_SCOPES
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import fake_get_image, fake_post_request
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def mock_config_entry_fixture(hass):
|
||||
def mock_config_entry_fixture(hass: HomeAssistant) -> MockConfigEntry:
|
||||
"""Mock a config entry."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain="netatmo",
|
||||
@ -55,7 +57,7 @@ def mock_config_entry_fixture(hass):
|
||||
|
||||
|
||||
@pytest.fixture(name="netatmo_auth")
|
||||
def netatmo_auth():
|
||||
def netatmo_auth() -> AsyncMock:
|
||||
"""Restrict loaded platforms to list given."""
|
||||
with patch(
|
||||
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth"
|
||||
|
@ -1,10 +1,10 @@
|
||||
"""The tests for Netatmo camera."""
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pyatmo
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.camera import STATE_STREAMING
|
||||
@ -14,21 +14,21 @@ from homeassistant.components.netatmo.const import (
|
||||
SERVICE_SET_PERSON_AWAY,
|
||||
SERVICE_SET_PERSONS_HOME,
|
||||
)
|
||||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
from homeassistant.const import CONF_WEBHOOK_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .common import fake_post_request, selected_platforms, simulate_webhook
|
||||
|
||||
from tests.common import async_capture_events, async_fire_time_changed
|
||||
from tests.common import MockConfigEntry, async_capture_events, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_setup_component_with_webhook(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test setup with webhook."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -134,10 +134,10 @@ IMAGE_BYTES_FROM_STREAM = b"test stream image bytes"
|
||||
|
||||
|
||||
async def test_camera_image_local(
|
||||
hass: HomeAssistant, config_entry, requests_mock: requests_mock.Mocker, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test retrieval or local camera image."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -162,10 +162,10 @@ async def test_camera_image_local(
|
||||
|
||||
|
||||
async def test_camera_image_vpn(
|
||||
hass: HomeAssistant, config_entry, requests_mock: requests_mock.Mocker, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test retrieval of remote camera image."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -188,10 +188,10 @@ async def test_camera_image_vpn(
|
||||
|
||||
|
||||
async def test_service_set_person_away(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set person as away."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -227,10 +227,10 @@ async def test_service_set_person_away(
|
||||
|
||||
|
||||
async def test_service_set_person_away_invalid_person(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set invalid person as away."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -255,10 +255,10 @@ async def test_service_set_person_away_invalid_person(
|
||||
|
||||
|
||||
async def test_service_set_persons_home_invalid_person(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set invalid persons as home."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -283,10 +283,10 @@ async def test_service_set_persons_home_invalid_person(
|
||||
|
||||
|
||||
async def test_service_set_persons_home(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set persons as home."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -309,10 +309,10 @@ async def test_service_set_persons_home(
|
||||
|
||||
|
||||
async def test_service_set_camera_light(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set the outdoor camera light mode."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -341,10 +341,10 @@ async def test_service_set_camera_light(
|
||||
|
||||
|
||||
async def test_service_set_camera_light_invalid_type(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service to set the indoor camera light mode."""
|
||||
with selected_platforms(["camera"]):
|
||||
with selected_platforms([Platform.CAMERA]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -371,11 +371,13 @@ async def test_service_set_camera_light_invalid_type(
|
||||
assert "NACamera <Hall> does not have a floodlight" in excinfo.value.args[0]
|
||||
|
||||
|
||||
async def test_camera_reconnect_webhook(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_camera_reconnect_webhook(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test webhook event on camera reconnect."""
|
||||
fake_post_hits = 0
|
||||
|
||||
async def fake_post(*args, **kwargs):
|
||||
async def fake_post(*args: Any, **kwargs: Any):
|
||||
"""Fake error during requesting backend data."""
|
||||
nonlocal fake_post_hits
|
||||
fake_post_hits += 1
|
||||
@ -427,7 +429,7 @@ async def test_camera_reconnect_webhook(hass: HomeAssistant, config_entry) -> No
|
||||
|
||||
|
||||
async def test_webhook_person_event(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test that person events are handled."""
|
||||
with selected_platforms(["camera"]):
|
||||
@ -465,7 +467,9 @@ async def test_webhook_person_event(
|
||||
assert test_netatmo_event
|
||||
|
||||
|
||||
async def test_setup_component_no_devices(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_component_no_devices(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test setup with no devices."""
|
||||
fake_post_hits = 0
|
||||
|
||||
@ -495,12 +499,12 @@ async def test_setup_component_no_devices(hass: HomeAssistant, config_entry) ->
|
||||
|
||||
|
||||
async def test_camera_image_raises_exception(
|
||||
hass: HomeAssistant, config_entry, requests_mock: requests_mock.Mocker
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test setup with no devices."""
|
||||
fake_post_hits = 0
|
||||
|
||||
async def fake_post(*args, **kwargs):
|
||||
async def fake_post(*args: Any, **kwargs: Any):
|
||||
"""Return fake data."""
|
||||
nonlocal fake_post_hits
|
||||
fake_post_hits += 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""The tests for the Netatmo climate platform."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from voluptuous.error import MultipleInvalid
|
||||
@ -31,19 +31,26 @@ from homeassistant.components.netatmo.const import (
|
||||
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
|
||||
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, CONF_WEBHOOK_ID
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_WEBHOOK_ID,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .common import selected_platforms, simulate_webhook
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_webhook_event_handling_thermostats(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service and webhook event handling with thermostats."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -214,10 +221,10 @@ async def test_webhook_event_handling_thermostats(
|
||||
|
||||
|
||||
async def test_service_preset_mode_frost_guard_thermostat(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service with frost guard preset for thermostats."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -287,10 +294,10 @@ async def test_service_preset_mode_frost_guard_thermostat(
|
||||
|
||||
|
||||
async def test_service_preset_modes_thermostat(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service with preset modes for thermostats."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -367,10 +374,10 @@ async def test_service_preset_modes_thermostat(
|
||||
|
||||
|
||||
async def test_service_set_temperature_with_end_datetime(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service setting temperature with an end datetime."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -425,10 +432,10 @@ async def test_service_set_temperature_with_end_datetime(
|
||||
|
||||
|
||||
async def test_service_set_temperature_with_time_period(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service setting temperature with an end datetime."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -483,10 +490,10 @@ async def test_service_set_temperature_with_time_period(
|
||||
|
||||
|
||||
async def test_service_clear_temperature_setting(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service clearing temperature setting."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -564,10 +571,10 @@ async def test_service_clear_temperature_setting(
|
||||
|
||||
|
||||
async def test_webhook_event_handling_no_data(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service and webhook event handling with erroneous data."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -618,7 +625,7 @@ async def test_service_schedule_thermostats(
|
||||
hass: HomeAssistant, config_entry, caplog: pytest.LogCaptureFixture, netatmo_auth
|
||||
) -> None:
|
||||
"""Test service for selecting Netatmo schedule with thermostats."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -671,7 +678,7 @@ async def test_service_preset_mode_with_end_time_thermostats(
|
||||
hass: HomeAssistant, config_entry, caplog: pytest.LogCaptureFixture, netatmo_auth
|
||||
) -> None:
|
||||
"""Test service for set preset mode with end datetime for Netatmo thermostats."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -740,10 +747,10 @@ async def test_service_preset_mode_with_end_time_thermostats(
|
||||
|
||||
|
||||
async def test_service_preset_mode_already_boost_valves(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service with boost preset for valves when already in boost mode."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -820,10 +827,10 @@ async def test_service_preset_mode_already_boost_valves(
|
||||
|
||||
|
||||
async def test_service_preset_mode_boost_valves(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service with boost preset for valves."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -875,7 +882,7 @@ async def test_service_preset_mode_invalid(
|
||||
hass: HomeAssistant, config_entry, caplog: pytest.LogCaptureFixture, netatmo_auth
|
||||
) -> None:
|
||||
"""Test service with invalid preset."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -891,10 +898,10 @@ async def test_service_preset_mode_invalid(
|
||||
|
||||
|
||||
async def test_valves_service_turn_off(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service turn off for valves."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -943,10 +950,10 @@ async def test_valves_service_turn_off(
|
||||
|
||||
|
||||
async def test_valves_service_turn_on(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service turn on for valves."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -990,10 +997,10 @@ async def test_valves_service_turn_on(
|
||||
|
||||
|
||||
async def test_webhook_home_id_mismatch(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service turn on for valves."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -1030,10 +1037,10 @@ async def test_webhook_home_id_mismatch(
|
||||
|
||||
|
||||
async def test_webhook_set_point(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test service turn on for valves."""
|
||||
with selected_platforms(["climate"]):
|
||||
with selected_platforms([Platform.CLIMATE]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""The tests for Netatmo cover."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
@ -9,17 +9,19 @@ from homeassistant.components.cover import (
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_STOP_COVER,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import selected_platforms
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_cover_setup_and_services(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test setup and services."""
|
||||
with selected_platforms(["cover"]):
|
||||
with selected_platforms([Platform.COVER]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
@ -9,6 +9,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import fake_post_request
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
@ -17,7 +18,7 @@ async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
config_entry,
|
||||
config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
with patch(
|
||||
|
@ -9,7 +9,7 @@ import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.netatmo import DOMAIN
|
||||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
from homeassistant.const import CONF_WEBHOOK_ID, Platform
|
||||
from homeassistant.core import CoreState, HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
@ -54,7 +54,9 @@ FAKE_WEBHOOK = {
|
||||
}
|
||||
|
||||
|
||||
async def test_setup_component(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_component(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test setup and teardown of the netatmo component."""
|
||||
with patch(
|
||||
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
|
||||
@ -86,7 +88,9 @@ async def test_setup_component(hass: HomeAssistant, config_entry) -> None:
|
||||
assert not hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
|
||||
async def test_setup_component_with_config(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_component_with_config(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test setup of the netatmo component with dev account."""
|
||||
fake_post_hits = 0
|
||||
|
||||
@ -127,7 +131,9 @@ async def test_setup_component_with_webhook(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
) -> None:
|
||||
"""Test setup and teardown of the netatmo component with webhook registration."""
|
||||
with selected_platforms(["camera", "climate", "light", "sensor"]):
|
||||
with selected_platforms(
|
||||
[Platform.CAMERA, Platform.CLIMATE, Platform.LIGHT, Platform.SENSOR]
|
||||
):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -155,7 +161,7 @@ async def test_setup_component_with_webhook(
|
||||
|
||||
|
||||
async def test_setup_without_https(
|
||||
hass: HomeAssistant, config_entry, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test if set up with cloud link and without https."""
|
||||
hass.config.components.add("cloud")
|
||||
@ -182,7 +188,9 @@ async def test_setup_without_https(
|
||||
assert "https and port 443 is required to register the webhook" in caplog.text
|
||||
|
||||
|
||||
async def test_setup_with_cloud(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_with_cloud(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test if set up with active cloud subscription."""
|
||||
await mock_cloud(hass)
|
||||
await hass.async_block_till_done()
|
||||
@ -296,7 +304,9 @@ async def test_setup_with_cloudhook(hass: HomeAssistant) -> None:
|
||||
assert not hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
|
||||
async def test_setup_component_with_delay(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_component_with_delay(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test setup of the netatmo component with delayed startup."""
|
||||
hass.state = CoreState.not_running
|
||||
|
||||
@ -404,7 +414,9 @@ async def test_setup_component_invalid_token_scope(hass: HomeAssistant) -> None:
|
||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
|
||||
|
||||
async def test_setup_component_invalid_token(hass: HomeAssistant, config_entry) -> None:
|
||||
async def test_setup_component_invalid_token(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test handling of invalid token."""
|
||||
|
||||
async def fake_ensure_valid_token(*args, **kwargs):
|
||||
|
@ -12,11 +12,12 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import FAKE_WEBHOOK_ACTIVATION, selected_platforms, simulate_webhook
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.test_util.aiohttp import AiohttpClientMockResponse
|
||||
|
||||
|
||||
async def test_camera_light_setup_and_services(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test camera ligiht setup and services."""
|
||||
with selected_platforms(["light"]):
|
||||
@ -127,7 +128,7 @@ async def test_setup_component_no_devices(hass: HomeAssistant, config_entry) ->
|
||||
|
||||
|
||||
async def test_light_setup_and_services(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test setup and services."""
|
||||
with selected_platforms(["light"]):
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""The tests for the Netatmo climate platform."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@ -13,9 +13,14 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import selected_platforms, simulate_webhook
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_select_schedule_thermostats(
|
||||
hass: HomeAssistant, config_entry, caplog: pytest.LogCaptureFixture, netatmo_auth
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
netatmo_auth: AsyncMock,
|
||||
) -> None:
|
||||
"""Test service for selecting Netatmo schedule with thermostats."""
|
||||
with selected_platforms(["climate", "select"]):
|
||||
|
@ -1,18 +1,23 @@
|
||||
"""The tests for the Netatmo sensor platform."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.netatmo import sensor
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import TEST_TIME, selected_platforms
|
||||
from .common import selected_platforms
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_indoor_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||
async def test_indoor_sensor(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test indoor sensor setup."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
with selected_platforms([Platform.SENSOR]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -25,9 +30,11 @@ async def test_indoor_sensor(hass: HomeAssistant, config_entry, netatmo_auth) ->
|
||||
assert hass.states.get(f"{prefix}pressure").state == "1014.5"
|
||||
|
||||
|
||||
async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -> None:
|
||||
async def test_weather_sensor(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test weather sensor unreachable."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
with selected_platforms([Platform.SENSOR]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -38,10 +45,10 @@ async def test_weather_sensor(hass: HomeAssistant, config_entry, netatmo_auth) -
|
||||
|
||||
|
||||
async def test_public_weather_sensor(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test public weather sensor setup."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
with selected_platforms([Platform.SENSOR]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -93,7 +100,7 @@ async def test_public_weather_sensor(
|
||||
("strength", "expected"),
|
||||
[(50, "Full"), (60, "High"), (80, "Medium"), (90, "Low")],
|
||||
)
|
||||
async def test_process_wifi(strength, expected) -> None:
|
||||
async def test_process_wifi(strength: int, expected: str) -> None:
|
||||
"""Test wifi strength translation."""
|
||||
assert sensor.process_wifi(strength) == expected
|
||||
|
||||
@ -102,7 +109,7 @@ async def test_process_wifi(strength, expected) -> None:
|
||||
("strength", "expected"),
|
||||
[(50, "Full"), (70, "High"), (80, "Medium"), (90, "Low")],
|
||||
)
|
||||
async def test_process_rf(strength, expected) -> None:
|
||||
async def test_process_rf(strength: int, expected: str) -> None:
|
||||
"""Test radio strength translation."""
|
||||
assert sensor.process_rf(strength) == expected
|
||||
|
||||
@ -111,7 +118,7 @@ async def test_process_rf(strength, expected) -> None:
|
||||
("health", "expected"),
|
||||
[(4, "Unhealthy"), (3, "Poor"), (2, "Fair"), (1, "Fine"), (0, "Healthy")],
|
||||
)
|
||||
async def test_process_health(health, expected) -> None:
|
||||
async def test_process_health(health: int, expected: str) -> None:
|
||||
"""Test health index translation."""
|
||||
assert sensor.process_health(health) == expected
|
||||
|
||||
@ -182,10 +189,15 @@ async def test_process_health(health, expected) -> None:
|
||||
],
|
||||
)
|
||||
async def test_weather_sensor_enabling(
|
||||
hass: HomeAssistant, config_entry, uid, name, expected, netatmo_auth
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
uid: str,
|
||||
name: str,
|
||||
expected: str,
|
||||
netatmo_auth: AsyncMock,
|
||||
) -> None:
|
||||
"""Test enabling of by default disabled sensors."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(["sensor"]):
|
||||
with selected_platforms([Platform.SENSOR]):
|
||||
states_before = len(hass.states.async_all())
|
||||
assert hass.states.get(f"sensor.{name}") is None
|
||||
|
||||
@ -206,12 +218,10 @@ async def test_weather_sensor_enabling(
|
||||
|
||||
|
||||
async def test_climate_battery_sensor(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test climate device battery sensor."""
|
||||
with patch("time.time", return_value=TEST_TIME), selected_platforms(
|
||||
["sensor", "climate"]
|
||||
):
|
||||
with selected_platforms([Platform.CLIMATE, Platform.SENSOR]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
@ -1,22 +1,24 @@
|
||||
"""The tests for Netatmo switch."""
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homeassistant.components.switch import (
|
||||
DOMAIN as SWITCH_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import selected_platforms
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_switch_setup_and_services(
|
||||
hass: HomeAssistant, config_entry, netatmo_auth
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test setup and services."""
|
||||
with selected_platforms(["switch"]):
|
||||
with selected_platforms([Platform.SWITCH]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
Loading…
x
Reference in New Issue
Block a user