async def setup_spike(hass) -> AsyncGenerator: """Set up general channel.""" MockConfigEntry( domain="amberelectric", data={ CONF_SITE_NAME: "mock_title", CONF_API_TOKEN: MOCK_API_TOKEN, CONF_SITE_ID: GENERAL_ONLY_SITE_ID, }, ).add_to_hass(hass) instance = Mock() with patch( "amberelectric.api.AmberApi.create", return_value=instance, ) as mock_update: general_channel: list[CurrentInterval] = [ generate_current_interval( ChannelType.GENERAL, parser.parse("2021-09-21T08:30:00+10:00")), ] general_channel[0].spike_status = SpikeStatus.SPIKE instance.get_current_price = Mock(return_value=general_channel) assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() yield mock_update.return_value
async def test_fetch_spike(hass: HomeAssistant, current_price_api: Mock) -> None: """Test fetching a site with only a general channel.""" general_channel: list[CurrentInterval] = [ generate_current_interval( ChannelType.GENERAL, parser.parse("2021-09-21T08:30:00+10:00") ), ] general_channel[0].spike_status = SpikeStatus.SPIKE current_price_api.get_current_price.return_value = general_channel data_service = AmberUpdateCoordinator(hass, current_price_api, GENERAL_ONLY_SITE_ID) result = await data_service._async_update_data() assert result["grid"]["price_spike"] == "spike"