mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Increase test coverage for Nest SDM integration (#44718)
This commit is contained in:
parent
c4b11322c8
commit
051f6c0e72
@ -580,13 +580,8 @@ omit =
|
|||||||
homeassistant/components/neato/vacuum.py
|
homeassistant/components/neato/vacuum.py
|
||||||
homeassistant/components/nederlandse_spoorwegen/sensor.py
|
homeassistant/components/nederlandse_spoorwegen/sensor.py
|
||||||
homeassistant/components/nello/lock.py
|
homeassistant/components/nello/lock.py
|
||||||
homeassistant/components/nest/__init__.py
|
|
||||||
homeassistant/components/nest/api.py
|
homeassistant/components/nest/api.py
|
||||||
homeassistant/components/nest/binary_sensor.py
|
|
||||||
homeassistant/components/nest/camera.py
|
|
||||||
homeassistant/components/nest/climate.py
|
|
||||||
homeassistant/components/nest/legacy/*
|
homeassistant/components/nest/legacy/*
|
||||||
homeassistant/components/nest/sensor.py
|
|
||||||
homeassistant/components/netatmo/__init__.py
|
homeassistant/components/netatmo/__init__.py
|
||||||
homeassistant/components/netatmo/api.py
|
homeassistant/components/netatmo/api.py
|
||||||
homeassistant/components/netatmo/camera.py
|
homeassistant/components/netatmo/camera.py
|
||||||
|
@ -253,3 +253,41 @@ async def test_unknown_event(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(events) == 0
|
assert len(events) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unknown_device_id(hass):
|
||||||
|
"""Test a pubsub message for an unknown event type."""
|
||||||
|
events = async_capture_events(hass, NEST_EVENT)
|
||||||
|
subscriber = await async_setup_devices(
|
||||||
|
hass,
|
||||||
|
"sdm.devices.types.DOORBELL",
|
||||||
|
create_device_traits("sdm.devices.traits.DoorbellChime"),
|
||||||
|
)
|
||||||
|
await subscriber.async_receive_event(
|
||||||
|
create_event("sdm.devices.events.DoorbellChime.Chime", "invalid-device-id")
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_event_message_without_device_event(hass):
|
||||||
|
"""Test a pubsub message for an unknown event type."""
|
||||||
|
events = async_capture_events(hass, NEST_EVENT)
|
||||||
|
subscriber = await async_setup_devices(
|
||||||
|
hass,
|
||||||
|
"sdm.devices.types.DOORBELL",
|
||||||
|
create_device_traits("sdm.devices.traits.DoorbellChime"),
|
||||||
|
)
|
||||||
|
timestamp = utcnow()
|
||||||
|
event = EventMessage(
|
||||||
|
{
|
||||||
|
"eventId": "some-event-id",
|
||||||
|
"timestamp": timestamp.isoformat(timespec="seconds"),
|
||||||
|
},
|
||||||
|
auth=None,
|
||||||
|
)
|
||||||
|
await subscriber.async_receive_event(event)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == 0
|
||||||
|
@ -7,11 +7,12 @@ and failure modes.
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from google_nest_sdm.exceptions import GoogleNestException
|
from google_nest_sdm.exceptions import AuthException, GoogleNestException
|
||||||
|
|
||||||
from homeassistant.components.nest import DOMAIN
|
from homeassistant.components.nest import DOMAIN
|
||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
ENTRY_STATE_LOADED,
|
ENTRY_STATE_LOADED,
|
||||||
|
ENTRY_STATE_NOT_LOADED,
|
||||||
ENTRY_STATE_SETUP_ERROR,
|
ENTRY_STATE_SETUP_ERROR,
|
||||||
ENTRY_STATE_SETUP_RETRY,
|
ENTRY_STATE_SETUP_RETRY,
|
||||||
)
|
)
|
||||||
@ -42,7 +43,7 @@ async def async_setup_sdm(hass, config=CONFIG):
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation"
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation"
|
||||||
):
|
):
|
||||||
await async_setup_component(hass, DOMAIN, config)
|
return await async_setup_component(hass, DOMAIN, config)
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_configuration_failure(hass, caplog):
|
async def test_setup_configuration_failure(hass, caplog):
|
||||||
@ -50,7 +51,8 @@ async def test_setup_configuration_failure(hass, caplog):
|
|||||||
config = CONFIG.copy()
|
config = CONFIG.copy()
|
||||||
config[DOMAIN]["subscriber_id"] = "invalid-subscriber-format"
|
config[DOMAIN]["subscriber_id"] = "invalid-subscriber-format"
|
||||||
|
|
||||||
await async_setup_sdm(hass, config)
|
result = await async_setup_sdm(hass, config)
|
||||||
|
assert result
|
||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
@ -67,7 +69,8 @@ async def test_setup_susbcriber_failure(hass, caplog):
|
|||||||
"homeassistant.components.nest.GoogleNestSubscriber.start_async",
|
"homeassistant.components.nest.GoogleNestSubscriber.start_async",
|
||||||
side_effect=GoogleNestException(),
|
side_effect=GoogleNestException(),
|
||||||
), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
||||||
await async_setup_sdm(hass)
|
result = await async_setup_sdm(hass)
|
||||||
|
assert result
|
||||||
assert "Subscriber error:" in caplog.text
|
assert "Subscriber error:" in caplog.text
|
||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
@ -81,10 +84,54 @@ async def test_setup_device_manager_failure(hass, caplog):
|
|||||||
"homeassistant.components.nest.GoogleNestSubscriber.async_get_device_manager",
|
"homeassistant.components.nest.GoogleNestSubscriber.async_get_device_manager",
|
||||||
side_effect=GoogleNestException(),
|
side_effect=GoogleNestException(),
|
||||||
), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
), caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
||||||
await async_setup_sdm(hass)
|
result = await async_setup_sdm(hass)
|
||||||
|
assert result
|
||||||
assert len(caplog.messages) == 1
|
assert len(caplog.messages) == 1
|
||||||
assert "Device manager error:" in caplog.text
|
assert "Device manager error:" in caplog.text
|
||||||
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
assert len(entries) == 1
|
assert len(entries) == 1
|
||||||
assert entries[0].state == ENTRY_STATE_SETUP_RETRY
|
assert entries[0].state == ENTRY_STATE_SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
|
async def test_subscriber_auth_failure(hass, caplog):
|
||||||
|
"""Test configuration error."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.nest.GoogleNestSubscriber.start_async",
|
||||||
|
side_effect=AuthException(),
|
||||||
|
):
|
||||||
|
result = await async_setup_sdm(hass, CONFIG)
|
||||||
|
assert result
|
||||||
|
|
||||||
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
|
assert len(entries) == 1
|
||||||
|
assert entries[0].state == ENTRY_STATE_SETUP_ERROR
|
||||||
|
|
||||||
|
flows = hass.config_entries.flow.async_progress()
|
||||||
|
assert len(flows) == 1
|
||||||
|
assert flows[0]["step_id"] == "reauth_confirm"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_missing_subscriber_id(hass, caplog):
|
||||||
|
"""Test successful setup."""
|
||||||
|
config = CONFIG
|
||||||
|
del config[DOMAIN]["subscriber_id"]
|
||||||
|
with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
||||||
|
result = await async_setup_sdm(hass, config)
|
||||||
|
assert not result
|
||||||
|
assert "Configuration option" in caplog.text
|
||||||
|
|
||||||
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
|
assert len(entries) == 1
|
||||||
|
assert entries[0].state == ENTRY_STATE_NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
|
async def test_empty_config(hass, caplog):
|
||||||
|
"""Test successful setup."""
|
||||||
|
with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
||||||
|
result = await async_setup_component(hass, DOMAIN, {})
|
||||||
|
assert result
|
||||||
|
assert not caplog.records
|
||||||
|
|
||||||
|
entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
|
assert len(entries) == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user