26f81c14bf
###Fix # In light of submitting this as a pull request to the core of HA there have been some refactoring changes to comply with HA's style requirements #Sensor names now moved to strings file to allow for translations #Coordinator now properly handles multiple devices #Spelling of signal strength sensor corrected ###Feature #Tests added
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""Tests for the Owlet integration."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
from homeassistant.components.owlet.const import (
|
|
CONF_OWLET_EXPIRY,
|
|
CONF_OWLET_REFRESH,
|
|
DOMAIN,
|
|
POLLING_INTERVAL,
|
|
)
|
|
from homeassistant.const import (
|
|
CONF_API_TOKEN,
|
|
CONF_REGION,
|
|
CONF_SCAN_INTERVAL,
|
|
CONF_USERNAME,
|
|
)
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry, load_fixture
|
|
|
|
|
|
async def async_init_integration(
|
|
hass: HomeAssistant,
|
|
skip_setup: bool = False,
|
|
properties_fixture: str = "update_properties_charging.json",
|
|
devices_fixture: str = "get_devices.json",
|
|
) -> MockConfigEntry:
|
|
"""Set up integration entry."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
title="sample@gmail.com",
|
|
unique_id="sample@gmail.com",
|
|
data={
|
|
CONF_REGION: "europe",
|
|
CONF_USERNAME: "sample@gmail.com",
|
|
CONF_API_TOKEN: "api_token",
|
|
CONF_OWLET_EXPIRY: 100,
|
|
CONF_OWLET_REFRESH: "refresh_token",
|
|
},
|
|
options={CONF_SCAN_INTERVAL: POLLING_INTERVAL},
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
if not skip_setup:
|
|
with patch(
|
|
"homeassistant.components.owlet.OwletAPI.get_properties",
|
|
return_value=json.loads(load_fixture(properties_fixture, "owlet")),
|
|
), patch(
|
|
"homeassistant.components.owlet.OwletAPI.authenticate", return_value=None
|
|
), patch(
|
|
"homeassistant.components.owlet.OwletAPI.get_devices",
|
|
return_value=json.loads(load_fixture(devices_fixture, "owlet")),
|
|
):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return entry
|