core/tests/components/anova/test_init.py

76 lines
2.6 KiB
Python
Raw Normal View History

Add Anova integration (#86254) * init setup of Anova Sous Vide * bump anova-wifi to 0.2.4 * Removed yaml support * Bump to anova-wifi 0.2.5 * Added support for adding sous vide while offline * Added basic test for sensor * added better tests for sensors and init * expanded code coverage * Decreased timedelta to lowest functioning value. * Updating my username * migrate to async_forward_entry_setups * applying pr recommended changes * bump anova-wifi to 0.2.7 * Improvements to hopefully get this review ready * formatting changes * clean ups for pr review * remove unneeded unique id check. * bump ao anova_wifi 0.3.0 * rename device_id to device_unique_id * renamed to 'anova' * added unique_id to MockConfigEntry * removed leftover anova sous vides * added device id to strings * added error for incorrect device id * add has_entity_name * added attr name for tests * added authentication functionality * bump to 0.4.3 * split entity into its own class/object * pulling firmware version out of async_setup Co-authored-by: J. Nick Koston <nick@koston.org> * addressed pr changes * fixed pytest * added anova data model * removed unneeded time change * add logging in package * rework step_user * Update homeassistant/components/anova/sensor.py Co-authored-by: J. Nick Koston <nick@koston.org> * Removed lower from attr unique id Co-authored-by: J. Nick Koston <nick@koston.org> * Removed unneeded member variables in sensor Co-authored-by: J. Nick Koston <nick@koston.org> * removed repeated subclass attr Co-authored-by: J. Nick Koston <nick@koston.org> * simplify update_failed test * created descriptionentity * bump to 0.6.1 limit ws connect * add translation for sensor entities * version bump - support pro model * add anova to strict typing * fixed sensor not getting datas type * Apply suggestions from code review Co-authored-by: J. Nick Koston <nick@koston.org> * Check for new devices in init * style changes * return false instead of config entry not ready * move serialize_device_list to utils * move repeating device check into api * moved unneeded code out of try except * fixed tests to get 100% cov * Update homeassistant/components/anova/strings.json Co-authored-by: J. Nick Koston <nick@koston.org> --------- Co-authored-by: J. Nick Koston <nick@koston.org>
2023-04-22 23:05:14 +00:00
"""Test init for Anova."""
from unittest.mock import patch
from anova_wifi import AnovaApi
from homeassistant.components.anova import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from . import ONLINE_UPDATE, async_init_integration, create_entry
async def test_async_setup_entry(hass: HomeAssistant, anova_api: AnovaApi) -> None:
"""Test a successful setup entry."""
await async_init_integration(hass)
state = hass.states.get("sensor.anova_precision_cooker_mode")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == "Low water"
async def test_wrong_login(
hass: HomeAssistant, anova_api_wrong_login: AnovaApi
) -> None:
"""Test for setup failure if connection to Anova is missing."""
entry = create_entry(hass)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
assert entry.state is ConfigEntryState.SETUP_ERROR
async def test_new_devices(hass: HomeAssistant, anova_api: AnovaApi) -> None:
"""Test for if we find a new device on init."""
entry = create_entry(hass, "test_device_2")
with patch(
"homeassistant.components.anova.coordinator.AnovaPrecisionCooker.update"
) as update_patch:
update_patch.return_value = ONLINE_UPDATE
assert len(entry.data["devices"]) == 1
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(entry.data["devices"]) == 2
async def test_device_cached_but_offline(
hass: HomeAssistant, anova_api_no_devices: AnovaApi
) -> None:
"""Test if we have previously seen a device, but it was offline on startup."""
entry = create_entry(hass)
with patch(
"homeassistant.components.anova.coordinator.AnovaPrecisionCooker.update"
) as update_patch:
update_patch.return_value = ONLINE_UPDATE
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert len(entry.data["devices"]) == 1
state = hass.states.get("sensor.anova_precision_cooker_mode")
assert state is not None
assert state.state == "Low water"
async def test_unload_entry(hass: HomeAssistant, anova_api: AnovaApi) -> None:
"""Test successful unload of entry."""
entry = await async_init_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state is ConfigEntryState.LOADED
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.NOT_LOADED