Fastdotcom service optimization (#107179)

* Startup mechanic

* Workable service (again)

* Optimized version, for now

* Minor refactoring

* Test cases

* Fixing test case

* Adding startup comment

* State_unknown added

* Update homeassistant/components/fastdotcom/services.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Check if config entries are not found

* Update tests/components/fastdotcom/test_service.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/fastdotcom/services.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/fastdotcom/services.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Erwin Douna 2024-01-11 08:27:15 +01:00 committed by GitHub
parent e0457590d1
commit b08832a89a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 161 additions and 38 deletions

View file

@ -65,23 +65,25 @@ async def test_delayed_speedtest_during_startup(
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
"homeassistant.components.fastdotcom.coordinator.fast_com"
), patch.object(hass, "state", CoreState.starting):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == config_entries.ConfigEntryState.LOADED
state = hass.states.get("sensor.fast_com_download")
assert state is not None
# Assert state is unknown as coordinator is not allowed to start and fetch data yet
assert state.state == STATE_UNKNOWN
# Assert state is Unknown as fast.com isn't starting until HA has started
assert state.state is STATE_UNKNOWN
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
with patch(
"homeassistant.components.fastdotcom.coordinator.fast_com", return_value=5.0
):
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
state = hass.states.get("sensor.fast_com_download")
assert state is not None
assert state.state == "0"
assert state.state == "5.0"
assert config_entry.state == config_entries.ConfigEntryState.LOADED