hass-core/tests/components/workday/test_init.py
G Johansson f74103c57e
Add config flow to Workday (#72558)
* Initial commit Workday Config Flow

* Add tests

* Remove day_to_string

* new entity name, new depr. version, clean

* Use repairs for depr. warning

* Fix issue_registry moved

* tweaks

* hassfest

* Fix CI

* FlowResultType

* breaking version

* remove translation

* Fixes

* naming

* duplicates

* abort entries match

* add_suggested_values_to_schema

* various

* validate country

* abort_entries_match in option flow

* Remove country test

* remove country not exist string

* docstring exceptions

* easier

* break version

* unneeded check

* slim tests

* Fix import test

* Fix province in abort_match

* review comments

* Fix import province

* Add review fixes

* fix reviews

* Review fixes
2023-04-19 11:50:11 +02:00

51 lines
1.7 KiB
Python

"""Test Workday component setup process."""
from __future__ import annotations
from datetime import datetime
from freezegun.api import FrozenDateTimeFactory
from homeassistant import config_entries
from homeassistant.core import HomeAssistant
from homeassistant.util.dt import UTC
from . import TEST_CONFIG_EXAMPLE_1, TEST_CONFIG_WITH_PROVINCE, init_integration
async def test_load_unload_entry(hass: HomeAssistant) -> None:
"""Test load and unload entry."""
entry = await init_integration(hass, TEST_CONFIG_EXAMPLE_1)
state = hass.states.get("binary_sensor.workday_sensor")
assert state
await hass.config_entries.async_remove(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.workday_sensor")
assert not state
async def test_update_options(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test options update and config entry is reloaded."""
freezer.move_to(datetime(2023, 4, 12, 12, tzinfo=UTC)) # Monday
entry = await init_integration(hass, TEST_CONFIG_WITH_PROVINCE)
assert entry.state == config_entries.ConfigEntryState.LOADED
assert entry.update_listeners is not None
state = hass.states.get("binary_sensor.workday_sensor")
assert state.state == "on"
new_options = TEST_CONFIG_WITH_PROVINCE.copy()
new_options["add_holidays"] = ["2023-04-12"]
hass.config_entries.async_update_entry(entry, options=new_options)
await hass.async_block_till_done()
entry_check = hass.config_entries.async_get_entry("1")
assert entry_check.state == config_entries.ConfigEntryState.LOADED
state = hass.states.get("binary_sensor.workday_sensor")
assert state.state == "off"