mirror of
https://github.com/home-assistant/core.git
synced 2025-06-06 14:17:06 +00:00

* Move constant values to separate file * Move constant values to separate file * Add config flow to lastfm * Add tests * Add config flow to lastfm * Add tests * Add tests * Add tests * Add extra form for main user and autofill with friends * Add extra form for main user and autofill with friends * Add extra form for main user and autofill with friends * Add extra form for main user and autofill with friends * Add OptionsFlow * Add tests * Fix feedback * Fix feedback * Fix feedback * Fix feedback * Fix test * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Update config_flow.py * Update config_flow.py * Update config_flow.py * Update homeassistant/components/lastfm/config_flow.py Co-authored-by: G Johansson <goran.johansson@shiftit.se> * Add tests * Cleanup * Update config_flow.py * Update config_flow.py * Update config_flow.py * Fix test * Fix feedback * Codeowner lastfm * Fix feedback * Fix feedback * Parametrize errors * Parametrize errors * Parametrize errors * Finish tests --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""Tests for the lastfm sensor."""
|
|
|
|
from pylast import Track
|
|
|
|
from homeassistant.components.lastfm.const import DOMAIN, STATE_NOT_SCROBBLING
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import CONF_DATA, MockNetwork, patch_fetch_user
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_update_not_playing(hass: HomeAssistant) -> None:
|
|
"""Test update when no playing song."""
|
|
entry = MockConfigEntry(domain=DOMAIN, data={}, options=CONF_DATA)
|
|
entry.add_to_hass(hass)
|
|
with patch_fetch_user(None):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
entity_id = "sensor.testaccount1"
|
|
|
|
state = hass.states.get(entity_id)
|
|
|
|
assert state.state == STATE_NOT_SCROBBLING
|
|
|
|
|
|
async def test_update_playing(hass: HomeAssistant) -> None:
|
|
"""Test update when playing a song."""
|
|
entry = MockConfigEntry(domain=DOMAIN, data={}, options=CONF_DATA)
|
|
entry.add_to_hass(hass)
|
|
with patch_fetch_user(Track("artist", "title", MockNetwork("test"))):
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
entity_id = "sensor.testaccount1"
|
|
|
|
state = hass.states.get(entity_id)
|
|
|
|
assert state.state == "artist - title"
|